Basic types

The C language provides the four basic arithmetic type specifiers charintfloat and double, and the modifiers signedunsignedshortand long. The following table lists the permissible combinations to specify a large set of storage size-specific declarations.

TypeExplanationFormat Specifier
char Smallest addressable unit of the machine that can contain basic character set. It is an integer type. Actual type can be either signed or unsigned. It contains CHAR_BIT bits.[3]  %c
signed char Of the same size as char, but guaranteed to be signed. Capable of containing at leastthe [−127, +127] range;[3][4]  %c (or %hhi for numerical output)
unsigned char Of the same size as char, but guaranteed to be unsigned. Contains at least the [0, 255] range.[5]  %c (or %hhu for numerical output)
short
short int
signed short
signed short int
Short signed integer type. Capable of containing at least the [−32,767, +32,767] range;[3][4] thus, it is at least 16 bits in size. The negative value is −32767 (not −32768) due to the one's-complement and sign-magnitude representations allowed by the standard, though the two's-complement representation is much more common.[6]  %hi
unsigned short
unsigned short int
Short unsigned integer type. Contains at least the [0, 65535] range;[3][4]  %hu
int
signed
signed int
Basic signed integer type. Capable of containing at least the [−32,767, +32,767] range;[3][4] thus, it is at least 16 bits in size.  %i or %d
unsigned
unsigned int
Basic unsigned integer type. Contains at least the [0, 65535] range;[3][4]  %u
long
long int
signed long
signed long int
Long signed integer type. Capable of containing at least the [−2,147,483,647, +2,147,483,647] range;[3][4] thus, it is at least 32 bits in size.  %li
unsigned long
unsigned long int
Long unsigned integer type. Capable of containing at least the [0, 4,294,967,295] range;[3][4]  %lu
long long
long long int
signed long long
signed long long int
Long long signed integer type. Capable of containing at least the [−9,223,372,036,854,775,807, +9,223,372,036,854,775,807] range;[3][4] thus, it is at least 64 bits in size. Specified since the C99 version of the standard.  %lli
unsigned long long
unsigned long long int
Long long unsigned integer type. Contains at least the [0, +18,446,744,073,709,551,615] range;[3][4] Specified since the C99 version of the standard.  %llu
float Real floating-point type, usually referred to as a single-precision floating-point type. Actual properties unspecified (except minimum limits), however on most systems this is the IEEE 754 single-precision binary floating-point format. This format is required by the optional Annex F "IEC 60559 floating-point arithmetic". for formatted input:
%f %F for digital notation, or
%g %G, or
%e %E
%a %A
for scientific notation[7]
double Real floating-point type, usually referred to as a double-precision floating-point type. Actual properties unspecified (except minimum limits), however on most systems this is the IEEE 754 double-precision binary floating-point format. This format is required by the optional Annex F "IEC 60559 floating-point arithmetic".  %lf %lF
%lg  %lG
%le  %lE
%la %lA;[7]for formatted output, the length modifier l is optional.
long double Real floating-point type, usually mapped to an extended precision floating-point number format. Actual properties unspecified. Unlike types float and double, it can be either 80-bit floating point format, the non-IEEE "double-double" or IEEE 754 quadruple-precision floating-point format if a higher precision format is provided, otherwise it is the same as double. See the article on long double for details.  %Lf %LF
%Lg %LG
%Le %LE
%La %LA[7]

Boolean type

C99 added a boolean (true/false) type _Bool. Additionally, the new <stdbool.h> header defines bool as a convenient alias for this type, and also provides macros for true and false_Bool functions similarly to a normal integral type, with one exception: any assignments to a _Bool that are not 0 (false) are stored as 1 (true). This behavior exists to avoid integer overflows in implicit narrowing conversions. For example, in the following code:

unsigned char b = 256;

if (b) {
   /* do something */
}

b evaluates to false if unsigned char is 8 bits wide. This is because 256 does not fit in the data type, which results in the lower 8 bits of it being used, resulting in a zero value. However, changing the type causes the previous code to behave normally:

_Bool b = 256;

if (b) {
   /* do something */
}

You have no rights to post comments