Special Integer Types

These integer types have unique properties that set them apart from the other integer types.

int

The int data type (pronounced /ɪnt/, a contraction of “integer”) is a special type that is designated as the optimal type for arithmetic and logical operations because it is implemented as the native word size of the processor’s registers. Compilers often also include special optimizations to make typical uses of int even faster than other data types. The int type must be at least as wide as short. The int type should be used for general purpose arithmetic, when the programmer is sure that it will not be assigned a value outside its range, which is undefined behavior. Examples of recommended usage include:

  • Loop iterators and counters

  • Array indices

  • etc.

unsigned char

The primary purpose of the unsigned char data type is to represent and manipulate raw binary data. In C, unsigned char is synonymous with “byte”. It has several special properties to facilitate this:

  • The character types are the smallest units of addressable storage, and as such the sizeof (unsigned char) is always 1.

  • The unsigned char data type cannot have padding bits, and, since it is unsigned, this implies that it consists entirely of value bits, all of which can be predictably manipulated with arithmetic operations.

  • Any object can be treated an array of unsigned char (i.e. unsigned char[n]), where n is the size of the object in bytes. This is called an object’s object representation.

_Bool

The _Bool type is a special unsigned integer type can hold values of 0 or 1. Special conversion rules apply when converting values to _Bool: any value that is not 0 is converted to 1. The special-purpose stdbool.h header file defines user-friendly macros bool, true, and false, which expand to _Bool, 1, and 0, respectively.

Note

These were not added to the language as keywords, since pre-existing programs might have already defined the names bool, true, and false. If a program actually uses this data type, it should include the stdbool.h header and use the user-friendly macros it provides.