In the C programming language, data types constitute the semantics and characteristics of storage of data elements. They are expressed in the language syntax in form of declarations for memory locations or variables. Data types also determine the types of operations or methods of processing of data elements.
The C language provides basic arithmetic types, such as integer and real number types, and syntax to build array and compound types. The C standard library contains additional definitions of support types, that have additional properties, such as providing storage with an exact size, independent of the language implementation on specific hardware platforms.
Primary types Main types The C language provides the four basic arithmetic type specifiers , , and (as well as the Boolean type ), and the modifiers , , , and . The following table lists the permissible combinations in specifying a large set of storage size-specific declarations. Type Explanation Size (bits) Format specifier Range Suffix for decimal constants Boolean type, added in C23. (Previously added in C99, but its size and its range were not specified.) 1 (exact) %d 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 bits. ≥8 %c Of the same size as , but guaranteed to be signed. Capable of containing at least the range. ≥8 %c Of the same size as , but guaranteed to be unsigned. Contains at least the range. ≥8 %c Short signed integer type. Capable of containing at least the range. ≥16 %hi or %hd Short unsigned integer type. Contains at least the range. ≥16 %hu Basic signed integer type. Capable of containing at least the range. ≥16 %i or %d Basic unsigned integer type. Contains at least the range. ≥16 %u or Long signed integer type. Capable of containing at least the range. ≥32 %li or %ld or Long unsigned integer type. Capable of containing at least the range. ≥32 %lu both or and or Long long signed integer type. Capable of containing at least the range. Specified since the C99 version of the standard. ≥64 %lli or %lld or Long long unsigned integer type. Contains at least the range. Specified since the C99 version of the standard. ≥64 %llu both or and or 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 (32 bits). This format is required by the optional Annex F "IEC 60559 floating-point arithmetic". Converting from text: or 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 (64 bits). This format is required by the optional Annex F "IEC 60559 floating-point arithmetic". none Real floating-point type, usually mapped to an extended precision floating-point number format. Actual properties unspecified. It can be either x86 extended-precision floating-point format (80 bits, but typically 96 bits or 128 bits in memory with padding bytes), the non-IEEE "double-double" (128 bits), IEEE 754 quadruple-precision floating-point format (128 bits), or the same as double. See the article on long double for details. %Lf %LF%Lg %LG%Le %LE%La %LA or
The actual size of the integer types varies by implementation. The standard requires only size relations between the data types and minimum sizes for each data type:
The relation requirements are that the is not smaller than , which is not smaller than , which is not smaller than . As 's size is always the minimum supported data type, no other data types (except bit-fields) can be smaller.
The minimum size for is 8 bits, the minimum size for and is 16 bits, for it is 32 bits and must contain at least 64 bits.
The type should be the integer type that the target processor is most efficiently working with. This allows great flexibility: for example, all types can be 64-bit. However, several different integer width schemes (data models) are popular. Because the data model defines how different programs communicate, a uniform data model is used within a given operating system application interface.
In practice, is usually 8 bits in size and is usually 16 bits in size (as are their unsigned counterparts). This holds true for platforms as diverse as 1990s SunOS 4 Unix, Microsoft MS-DOS, modern Linux, and Microchip MCC18 for embedded 8-bit PIC microcontrollers. POSIX requires to be exactly 8 bits in size.
Various rules in the C standard make the basic type used for arrays suitable to store arbitrary non-bit-field objects: its lack of padding bits and trap representations, the definition of object representation, and the possibility of aliasing.
The actual size and behavior of floating-point types also vary by implementation. The only requirement is that is not smaller than , which is not smaller than . Usually, the 32-bit and 64-bit IEEE 754 binary floating-point formats are used for and respectively.
The C99 standard includes new real floating-point types and , defined in <math.h>. They correspond to the types used for the intermediate results of floating-point expressions when is 0, 1, or 2. These types may be wider than .
C99 also added complex types: , , . C11 added imaginary types (which were described in an informative annex of C99): , , . Including the header <complex.h> allows all these types to be accessed with using and respectively.
Boolean type C99 added a Boolean data type . Additionally, the <stdbool.h> header defines as a convenient alias for this type, and also provides macros for true and false. functions similarly to a normal integer type, with one exception: any conversion to a gives 0 (false) if the value equals 0; otherwise, it gives 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 }
Variable b evaluates to false if has a size of 8 bits. This is because the value 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 }
The type also ensures true values always compare equal to each other:
_Bool a = 1; _Bool b = 2;
if (a == b) { // this code will run }
In C23, (and its values true and false) became a core functionality of the language (making the contents of <stdbool.h> obsolescent), allowing for the following examples of code:
bool b = true;
if (b) { // this code will run }
Bit-precise integer types Since C23, the language allows the programmer to define integers that have a width of an arbitrary number of bits. Those types are specified as , where N is an integer constant expression that denotes the number of bits, including the sign bit for signed types, represented in two's complement. The maximum value of N is provided by BITINT_MAXWIDTH and is at least ULLONG_WIDTH. Therefore, the type (or ) takes values from −2 to 1 while takes values from 0 to 3. The type also exists, being either 0 or 1 and has no equivalent signed type. A proposal for C2Y proposes to lift this restriction and allow which then has the possible values 0 and -1, removing the special case for .
Size and pointer difference types The C language specification includes the s and to represent memory-related quantities. Their size is defined according to the target processor's arithmetic capabilities, not the memory capabilities, such as available address space. Both of these types are defined in the <stddef.h> header.
is an unsigned integer type used to represent the size of any object (including arrays) in the particular implementation. The operator yields a value of the type . The maximum size of is provided via SIZE_MAX, a macro constant which is defined in the <stdint.h> header. is guaranteed to be at least 16 bits wide. Additionally, POSIX includes , which is a signed integer type of the same width as .
is a signed integer type used to represent the difference between pointers. It is guaranteed to be valid only against pointers of the same type; subtraction of pointers consisting of different types is implementation-defined.
Interface to the properties of the basic types Information about the actual properties, such as size, of the basic arithmetic types, is provided via macro constants in two headers: <limits.h> header defines macros for integer types and <float.h> header defines macros for floating-point types. The actual values depend on the implementation.
Properties of integer types CHAR_BIT – size of the char type in bits, commonly referred to as the size of a byte (at least 8 bits) SCHAR_MIN, SHRT_MIN, INT_MIN, LONG_MIN, LLONG_MIN(C99) – minimum possible value of signed integer types: signed char, signed short, signed int, signed long, signed long long SCHAR_MAX, SHRT_MAX, INT_MAX, LONG_MAX, LLONG_MAX(C99) – maximum possible value of signed integer types: signed char, signed short, signed int, signed long, signed long long UCHAR_MAX, USHRT_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX(C99) – maximum possible value of unsigned integer types: unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long CHAR_MIN – minimum possible value of char CHAR_MAX – maximum possible value of char MB_LEN_MAX – maximum number of bytes in a multibyte character BOOL_WIDTH (C23) - bit width of _Bool, always 1 CHAR_WIDTH (C23) - bit width of char; CHAR_WIDTH, UCHAR_WIDTH and SCHAR_WIDTH are equal to CHAR_BIT by definition SCHAR_WIDTH, SHRT_WIDTH, INT_WIDTH, LONG_WIDTH, LLONG_WIDTH (C23) - bit width of signed char, short, int, long, and long long respectively UCHAR_WIDTH, USHRT_WIDTH, UINT_WIDTH, ULONG_WIDTH, ULLONG_WIDTH (C23) - bit width of unsigned char, unsigned short, unsigned int, unsigned long, and unsigned long long respectively
Properties of floating-point types FLT_MIN, DBL_MIN, LDBL_MIN – minimum normalized positive value of float, double, long double respectively FLT_TRUE_MIN, DBL_TRUE_MIN, LDBL_TRUE_MIN (C11) – minimum positive value of float, double, long double respectively FLT_MAX, DBL_MAX, LDBL_MAX – maximum finite value of float, double, long double, respectively FLT_ROUNDS – rounding mode for floating-point operations FLT_EVAL_METHOD (C99) – evaluation method of expressions involving different floating-point types FLT_RADIX – radix of the exponent in the floating-point types FLT_DIG, DBL_DIG, LDBL_DIG – number of decimal digits that can be represented without losing precision by float, double, long double, respectively FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON – difference between 1.0 and the next representable value of float, double, long double, respectively FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG – number of FLT_RADIX-base digits in the floating-point significand for types float, double, long double, respectively FLT_MIN_EXP, DBL_MIN_EXP, LDBL_MIN_EXP – minimum negative integer such that FLT_RADIX raised to a power one less than that number is a normalized float, double, long double, respectively FLT_MIN_10_EXP, DBL_MIN_10_EXP, LDBL_MIN_10_EXP – minimum negative integer such that 10 raised to that power is a normalized float, double, long double, respectively FLT_MAX_EXP, DBL_MAX_EXP, LDBL_MAX_EXP – maximum positive integer such that FLT_RADIX raised to a power one less than that number is a normalized float, double, long double, respectively FLT_MAX_10_EXP, DBL_MAX_10_EXP, LDBL_MAX_10_EXP – maximum positive integer such that 10 raised to that power is a normalized float, double, long double, respectively