c/language/arithmetic types

{{rrev|since=c99|

Boolean type

 * (also accessible as the macro ) - type, capable of holding one of the two values: and  (also accessible as the macros  and ).

Note that to _Bool does not work the same as conversion to other integer types:  evaluates to, whereas  evaluates to. }}

Character types

 * - type for signed character representation.
 * - type for unsigned character representation. Also used to inspect (raw memory).
 * - type for character representation. Equivalent to either or  (which one is implementation-defined and may be controlled by a compiler commandline switch), but  is a distinct type, different from both  and.

Note that the standard library also defines names   to represent wide characters.

Integer types

 * (also accessible as, may use the keyword )
 * (also accessible as )
 * (also accessible as )
 * This is the most optimal integer type for the platform, and is guaranteed to be at least 16 bits. Most current systems use 32 bits (see Data models below).
 * (also accessible as ), the unsigned counterpart of, implementing modulo arithmetic. Suitable for bit manipulations.
 * (also accessible as )
 * (also accessible as )

Note: as with all type specifiers, any order is permitted: and  name the same type.

The following table summarizes all available integer types and their properties:

Besides the minimal bit counts, the C Standard guarantees that


 * == &le;  &le;  &le;  &le;.

Note: this allows the extreme case in which are sized 64 bits, all types (including ) are 64 bits wide, and  returns 1 for every type.

Note: integer arithmetic is defined differently for the signed and unsigned integer types. See, in particular.

Data models
The choices made by each implementation about the sizes of the fundamental types are collectively known as data model. Four data models found wide acceptance:

32 bit systems:


 * LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit)
 * Win16 API
 * ILP32 or 4/4/4 (int, long, and pointer are 32-bit);
 * Win32 API
 * Unix and Unix-like systems (Linux, Mac OS X)

64 bit systems:


 * LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit)
 * Win64 API
 * LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit)
 * Unix and Unix-like systems (Linux, Mac OS X)

Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. Unicos on Cray).

Note that exact-width integer types are available in since C99.

Real floating types
C has three types for representing real floating-point values:


 * - single precision floating-point type. Matches if supported.
 * - double precision floating-point type. Matches if supported.
 * - extended precision floating-point type. Matches if supported, otherwise matches  if supported, otherwise matches some non-IEEE-754 extended floating-point format as long as its precision is better than binary64 and range is at least as good as binary64, otherwise matches IEEE-754 binary64 format.
 * binary128 format is used by some HP-UX, SPARC, MIPS, ARM64, and z/OS implementations.
 * The most well known IEEE-754 binary64-extended format is 80-bit x87 extended precision format. It is used by many x86 and x86-64 implementations (a notable exception is MSVC, which implements in the same format as, i.e. binary64).

Floating-point types may support special values:
 * infinity (positive and negative), see
 * the negative zero, . It compares equal to the positive zero, but is meaningful in some arithmetic operations, e.g., but )
 * not-a-number (NaN), which does not compare equal with anything (including itself). Multiple bit patterns represent NaNs, see nan, . Note that C takes no special notice of signaling NaNs (specified by IEEE-754), and treats all NaNs as quiet.

Real floating-point numbers may be used with + - / * and various mathematical functions from. Both built-in operators and library functions may raise floating-point exceptions and set errno as described in.

Floating-point expressions may have greater range and precision than indicated by their types, see flt_eval_method. ,, and force the range and precision to the one associated with the declared type.

Floating-point expressions may also be contracted, that is, calculated as if all intermediate values have infinite range and precision, see.

Some operations on floating-point numbers are affected by and modify the state of the floating-point environment (most notably, the rounding direction).

are defined between real floating types and integer, complex, and imaginary types.

See Limits of floating-point types and the library for additional details, limits, and properties of the floating-point types.

{{rrev|since=c99|

Complex floating types
Complex floating types model the mathematical, that is the numbers that can be written as a sum of a real number and a real number multiplied by the imaginary unit: $a + bi$

The three complex types are
 * (also available as if  is included)
 * (also available as if  is included)
 * (also available as if  is included)

Note: as with all type specifiers, any order is permitted:, , and even name the same type.

Each complex type has the same and  as an  of two elements of the corresponding real type ( for,  for ,  for ). The first element of the array holds the real part, and the second element of the array holds the imaginary component.

Complex numbers may be used with + - * and /, possibly mixed with imaginary and real numbers. There are many mathematical functions defined for complex numbers in. Both built-in operators and library functions may raise floating-point exceptions and set errno as described in.

Increment and decrement are not defined for complex types.

Relational operators are not defined for complex types (there is no notion of "less than").

are defined between complex types and other arithmetic types.

In order to support the one-infinity model of complex number arithmetic, C regards any complex value with at least one infinite part as an infinity even if its other part is a NaN, guarantees that all operators and functions honor basic properties of infinities and provides cproj to map all infinities to the canonical one (see for the exact rules).

C also treats multiple infinities so as to preserve directional information where possible, despite the inherent limitations of the Cartesian representation:

multiplying the imaginary unit by real infinity gives the correctly-signed imaginary infinity: i × ∞ = i∞. Also, i × (∞ – i∞) = ∞ + i∞ indicates the reasonable quadrant.

Imaginary floating types
Imaginary floating types model the mathematical, that is numbers that can be written as a real number multiplied by the imaginary unit: $bi$ The three imaginary types are
 * (also available as if  is included)
 * (also available as if  is included)
 * (also available as if  is included)

Note: as with all type specifiers, any order is permitted:, , and even name the same type.

Each of the three imaginary types has the same and  as its corresponding real type ( for,  for ,  for ).

Note: despite that, imaginary types are distinct and with their corresponding real types, which prohibits aliasing.

Imaginary numbers may be used with + - * and /, possibly mixed with complex and real numbers. There are many mathematical functions defined for imaginary numbers in. Both built-in operators and library functions may raise floating-point exceptions and set errno as described in.

Increment and decrement are not defined for imaginary types.

are defined between imaginary types and other arithmetic types.

The imaginary numbers make it possible to express all complex numbers using the natural notation (where i is defined as _imaginary_i). Without imaginary types, certain special complex values cannot be created naturally. For example, if i is defined as _complex_i, then writing gives NaN as the real part, and  must be used instead. Same goes for the numbers with the negative zero imaginary component, which are meaningful when working with the library functions with branch cuts, such as csqrt: results in the positive zero imaginary component if i is defined as _complex_i and the negative zero imaginary part requires the use of cmplx or conj.

Imaginary types also simplify implementations; multiplication of an imaginary by a complex can be implemented straightforwardly with two multiplications if the imaginary types are supported, instead of four multiplications and two additions. }}

Range of values
The following table provides a reference for the limits of common numeric representations.

Prior to C23, the C Standard allowed any signed integer representation, and the minimum guaranteed range of N-bit signed integers was from to  (e.g. -127 to 127 for a signed 8-bit type), which corresponds to the limits of  or.

However, all popular data models (including all of ILP32, LP32, LP64, LLP64) and almost all C compilers use representation (the only known exceptions are some compliers for UNISYS), and as of C23, it is the only representation allowed by the standard, with the guaranteed range from  to  (e.g. -128 to 127 for a signed 8-bit type).

Note: actual (as opposed to guaranteed minimal) ranges are available in the library headers and.