1. The size of char should be at least 1 byte (most implementations will have sizeof(char)=1)
2. The size of short should be less than or equal to the size of int, and should be at least 2 bytes (most implementations will have sizeof(short)=2)
3. The size of int should be the machine word size (the optimal size that the system can handle at one go). Thus, a 16-bit compiler will have sizeof(int)=2 (16 bits = 2 bytes) whereas a 32-bit compiler will have sizeof(int)=4 (32 bits = 4 bytes)
4. The size of long should be greater than or equal to size of int, and should be at least 4 bytes (most implementations will have sizeof(long=4)
Thus, the following condition will always hold good, no matter which C compiler you use:
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
Typical values are shown below:
char | short | int | long | |
---|---|---|---|---|
16-bit platform | 1 | 2 | 2 | 4 |
32-bit platform | 1 | 2 | 4 | 4 |
64-bit platform | 1 | 2 | 8 | 8 |
Related Questions:
Q: Are char, short, int and long signed or unsigned by default?
Q: How do I choose between char, short, int and long?
Q: How do I find the ranges of char, short, int and long?
Q: What if I want something larger than long?
Q: Is C a middle-level language?
Related Articles
No user responded in this post