C provides the short, long, and long long type specifiers to modify the width and range of integer types. These modifiers can be used with int and have implementation-defined sizes subject to the minimum requirements of the C standard.
#include <stdio.h>
int main()
{
short int a = 100;
int b = 1000;
long int c = 100000L;
long long int d = 1000000000LL;
printf("short int = %zu bytes\n", sizeof(a));
printf("int = %zu bytes\n", sizeof(b));
printf("long int = %zu bytes\n", sizeof(c));
printf("long long int = %zu bytes\n", sizeof(d));
return 0;
}
Example Output #
The exact sizes depend on the implementation. A common result is:
short int = 2 bytes
int = 4 bytes
long int = 8 bytes
long long int = 8 bytes
Explanation #
The width modifiers used with integer types are:
short int
int
long int
long long int
The int keyword can be omitted when used with short, long, or long long:
short a;
long b;
long long c;
These are equivalent to:
short int a;
long int b;
long long int c;
Integer Width Modifier Table #
| Type | Minimum range requirement | Minimum width |
|---|---|---|
short int |
−32,767 to 32,767 | 16 bits |
int |
−32,767 to 32,767 | 16 bits |
long int |
−2,147,483,647 to 2,147,483,647 | 32 bits |
long long int |
−9,223,372,036,854,775,807 to 9,223,372,036,854,775,807 | 64 bits |
The standard guarantees ordering relationships between these types:
sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
The actual sizes can be larger. For example, on a platform where long is 8 bytes, long and long long can have the same size.
The suffixes on the integer constants in the example specify their intended types:
| Suffix | Literal type |
|---|---|
L |
long int |
LL |
long long int |
sizeof reports the actual size of the type on the implementation, in bytes.