Short int in C Programming
Short int in C is a data type in the C Programming language. Short int in C occupies 2 bytes of memory. Number Range of short int is −32,767 to +32,767.
Size of Different int Data Types
In terms of occupying memory the size of int, short int, will vary. To be more specific, int occupies four bytes of memory while short int occupies only two bytes of memory.
An interesting thing to learn is that in C programming language, short int or short reflects the same meaning.
In C programming language, sizeof() operator can be used to find the size of data type
Let us explore the size of int, short int in C by executing a C program:
Output
As, short and short int both are the same, from the output of the above program we can clearly say that size of short and short int in C is also the same ( two bytes). Also, from the output section do observe that the int data type occupies 4 bytes of memory.
For Integer, we have 8 possible types:
- int, unsigned int
- short, unsigned short
- long, unsigned long
- long long, unsigned long long
Now, Let us discuss them in detail
int, Unsigned int
Size of int data type is 4 bytes. Size of unsigned int data type is 4 bytes. The size of int may vary according to the compiler, a 32-bit compiler will give int size as 2 bytes whereas the 64-bit compiler will give 4 bytes. Let us confirm the size of int, unsigned int data type by executing a small C program:
Output
Also, note that the range of int is -2147483648 to 2147483647 while the range on unsigned int is 0 to 4294967295
short, Unsigned short
Size of short data type is 2 bytes. Size of unsigned short data type is 2 bytes.
Let us execute a C program to demonstrate the size of short, unsigned short data type:
Output
Also, note that the range of short is -32768 to 32767 while the range on unsigned short is 0 to 65535.
long, unsigned long
Size of long data type is 8 bytes. Size of unsigned long data type is 8 bytes.
Let us execute a C program to demonstrate the size of long, unsigned long data type:
Output
Also, note that the range of long is -9223372036854775808 to 9223372036854775807 while the range of unsigned long is 0 to 18446744073709551615.
long long, unsigned long long
Size of long long data type is 8 bytes. Size of unsigned long long data type is 8 bytes.
Let us execute a C program to demonstrate the size of long long, unsigned long long data type:
Output
Also, note that the range of long long -9223372036854775808 to 9223372036854775807 is while the range of unsigned long long is 0 to 18446744073709551615.
Learn More
By this point, we got a good idea about short in C. To explore and to be more knowledgable about short int and data types in C do refer our article.
Conclusion
- Short int or short portrays the same meaning.
- In C programming language, short is the integer data type that occupies two bytes of memory.
- The range of short int type is -32768 to 32767.