Type Specifier | length in bytes | Range | Example |
char | 1 | -128 to 127 | char x; |
unsigned char | 1 | 0 to 255 | unsigned char x; |
short | 2 | -32768 to 32767 | short x; or short int x; |
unsigned short | 2 | 0 to 65535 | unsigned short x; |
int | 4 | -2147483648 to 2147483647 | int x; |
unsigned int | 4 | 0 to 4294967295 | unsigned x; |
long | 4 | -2147483648 to 2147483647 | long x; or long int x; |
unsigned long | 4 | 0 to 4294967295 | unsigned long x; |
These are reasonable since, say, 4 bytes is 32 bits and 2^32 = 4294967295
These limits are specified in the standard C library header file "limits.h"
#include <iostream>
#include <limits.h>
#include <stdlib.h>
int main(void)
{
cout << " CHAR_MIN = " << CHAR_MIN << "CHAR_MAX = " << CHAR_MAX << endl;
cout << " SHRT_MIN = " << SHRT_MIN << "SHRT_MAX = " << SHRT_MAX << endl;
cout << " INT_MIN = " << INT_MIN << "INT_MAX = " << INT_MAX << endl;
cout << " LONG_MIN = " << LONG_MIN << "LONG_MAX = " << LONG_MAX << endl;
cout << "UCHAR_MAX = " << UCHAR_MAX << endl;
cout << "USHRT_MAX = " << USHRT_MAX << endl;
cout << " UINT_MAX = " << UINT_MAX << endl;
cout << " LONG_MAX = " << LONG_MAX << endl;
system("PAUSE");
return 0;
}
The output of this program will look like this:
CHAR_MIN = -128, CHAR_MAX = 127 SHRT_MIN = -32768, SHRT_MAX = 32767 INT_MIN = -2147483648, INT_MAX = 2147483647 LONG_MIN = -2147483648, LONG_MAX = 2147483647 UCHAR_MAX = 255 USHRT_MAX = 65535 UINT_MAX = 4294967295 LONG_MAX = 2147483647 Press any key to continue . . .