C Integer Types

Summary: in this tutorial, you will learn various C integer types including signed and unsigned integers.

C signed integer types

C provides you with five signed integer types. Each integer type has several synonyms.

The following table illustrates the first five integer types with their corresponding synonyms:

Integer Types

Synonyms

Notes

signed char

int

signed, signed int

short

short int, signed short, signed short int

long

long int, signed long, signed long int

long long

long long int, signed long long, signed long long int

Available since C99

C unsigned integer types

For each signed integer, C also provides the corresponding unsigned integer type that has the same memory size as the signed integer type.

The following table illustrates the unsigned integer type:

Signed Integer Types

unsigned Integer Types

char

unsigned char

int

unsigned int

short

unsigned short

long

unsigned long

long long

unsigned long long

C integer types value ranges

C defines exactly minimum storage size of each integer type e.g., short takes at least two byes, long takes at least 4 bytes. Regardless of the C’s implementation, the size of integer types must follows the order below:

1

sizeof(short)&lt;sizeof(int)&lt;sizeof(long)&lt;sizeof(longlong)

The following table gives you the common sizes of the integer types in C:

Type

Storage size

Minimum value

Maximum value

char

1 byte

-128

127

unsigned char

1 byte

0

255

signed char

1 byte

-128

127

int

2 bytes or 4 bytes

-32,768 or -2,147,483,648

32,767 or 2,147,483,647

unsigned int

2 bytes or 4 bytes

0

65,535 or 2,147,483,647

short

2 bytes

-32,768

32,767

unsigned short

2 bytes

0

65,535

long

4 bytes

-2,147,483,648

2,147,483,647

unsigned long

4 bytes

0

4,294,967,295

long long(C99)

8 bytes

-9,223,372,036, 854,775,808

9,223,372,036, 854,775,807

unsigned long long

8 bytes

0

18,446,744,073, 709,551,615

The value ranges of integer types can be found in the limits.hheader file. This header file contains the macros that define minimum and maximum values of each integer type e.g., INT_MIN, INT_MAX for minimum and maximum size of the integer.

Getting the sizes of integer types

To obtain the size of an integer type, or any type, you use the sizeof() operator. The following program demonstrates how to use the sizeof() operator to get the sizes of various integer types in your system.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

/*

* File : main.c

* Author : zentut.com

* Purpose: display sizes of integer types

*/

#include <stdio.h>

intmain()

{

printf("sizeof(short) = %d bytes\n",sizeof(short));

printf("sizeof(int) = %d bytes\n",sizeof(int));

printf("sizeof(unsigned int) = %d bytes\n",sizeof(unsignedint));

printf("sizeof(long) = %d bytes\n",sizeof(long));

return0;

}

The following is the output in our system:

1

2

3

4

sizeof(short)=2bytes

sizeof(int)=4bytes

sizeof(unsignedint)=4bytes

sizeof(long)=4bytes

In this tutorial, we have introduced various C integer types and shown you how to use the sizeof() operator to get the sizes of an integer types in your system.