Integer types and limits

suggest change

The standard signed integer types, in nondecreasing rank, are:

Except for signed char, the word signed is optional. Each signed type has a corresponding unsigned type with the same storage requirement and alignment.

char, signed char, and unsigned char are three distinct types. Whether plain char has the same range as its signed or unsigned counterpart is implementation-defined.

The standard specifies minimum ranges rather than fixed sizes:

Type Minimum required range
signed char −127 through 127
unsigned char 0 through 255
short −32767 through 32767
unsigned short 0 through 65535
int −32767 through 32767
unsigned int 0 through 65535
long −2147483647 through 2147483647
unsigned long 0 through 4294967295
long long −9223372036854775807 through 9223372036854775807
unsigned long long 0 through 18446744073709551615

<limits.h> provides the actual limits for the implementation, including CHAR_BIT, INT_MIN, INT_MAX, and ULONG_MAX. A C byte contains CHAR_BIT bits and is at least eight bits; it is not necessarily an eight-bit octet.

#include <limits.h>
#include <stdio.h>

int main(void)
{
    printf("int: %d through %d\n", INT_MIN, INT_MAX);
    printf("bits per byte: %d\n", CHAR_BIT);
}

<stdint.h> defines exact-width types such as uint32_t only when the implementation provides a type with exactly that width and no padding bits. It also provides minimum-width, fastest-width, pointer-capable, and maximum-width integer types.

An integer constant's type depends on its value, base, and suffix. See Integer constants; do not infer the type solely from the constant's spelling length.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents