Home » C programming language

Difference between short, short int and int data types in C programming



In this tutorial we will learn what is the difference between short, short int and int data types in c programming language?

short or short int

Both data types are same, short int can also be written as short; short occupies 2 bytes in the memory.

Here is the size and value range of short or short int

short or short int or signed short int 2 Bytes -32,768 to 32,767
unsigned short or unsigned short int 2 Bytes 0 to 65,535

Here is the proof

short, signed short or signed short int stores 15 bits of data, last bit represents sign

short size and range in c

unsigned short or unsigned short int stores 16 bits of data

unsigned short size and range

Consider this program:

int main()
{
    printf("size of short : %d\n",sizeof(short));
    printf("size of short int : %d\n",sizeof(short int));
    printf("size of signed short  : %d\n",sizeof(signed short));
    printf("size of signed short int  : %d\n",sizeof(signed short int));
    
    return 0;
}

Output

size of short : 2 
size of short int : 2 
size of signed short: 2 
size of signed short int: 2

int

Data type int (Integer) occupies 4 bytes in the memory.

Here is the size and value range of int

signed int or int 4 Bytes -2,147,483,648 to 2,147,483,647
unsigned int 4 Bytes 0 to 4,294,967,295

Here is the proof

signed int or int stores 31 bits of data, last bit represents sign

int data type size and range in c

unsigned int stores 32 bits of data

unsigned int data type size and range in c

Consider this program:

int main()
{

    printf("size of int : %d\n",sizeof(int));
    printf("size of signed int : %d\n",sizeof(signed int));
    printf("size of unsigned  : %d\n",sizeof(unsigned int));
    
    return 0;
}

Output

size of int : 4 
size of signed int : 4
size of unsigned: 4

Note: Size and data range may vary according to computer architecture, we are writing based on 32 bits computer architecture, compiler Linux GCC.






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.