C - Unsigned Integer Types


Some kinds of data are always positive. In such cases you don't need to provide for negative values.

For each type that stores signed integers, there is a corresponding type that stores unsigned integers.

The unsigned type occupies the same amount of memory as the signed type.

Each unsigned type name is the signed type name prefixed with the keyword unsigned.

The following table shows the basic set of unsigned integer types that you can use.

Type name Number of bytes
unsigned char 1
unsigned short or unsigned short int2
unsigned int4
unsigned long or unsigned long int 4
unsigned long long or unsigned long long int8

A 32-bit integer variable can represent any of 4,294,967,296 different values.

Using an unsigned type doesn't provide more values than the corresponding signed type.

It does allow numbers to be represented that are twice the magnitude.

Here are examples of unsigned integer variable declarations:

unsigned int count;
unsigned long population;