C Data Types

int (Integer)

The int type stores whole numbers. It typically occupies 4 bytes of memory and does not support decimals.

Loading...
Output:

float (Floating Point)

A float can store decimal values with less precision. Use %f for output.

Loading...
Output:

double (Double Precision)

double is like float, but with more precision and range (typically 8 bytes).

Loading...
Output:

char (Character)

char stores a single character using ASCII encoding. Use single quotes and the %c specifier.

Loading...
Output:

Size and Range

While actual sizes depend on your machine and compiler, here are common sizes:

  • int: 4 bytes
  • float: 4 bytes
  • double: 8 bytes
  • char: 1 byte

Type Mixing (Promotion)

If you mix different types in an expression, C automatically promotes smaller types. For example, adding an int and a float results in a float.

Loading...
Output:

Practice Question

What will this print?

A. 7
B. 7.0
C. error
Loading...
Output:

Hint: The integer a is promoted to a float before addition.

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic