Difference Between Short, Short Int And Int Data Types In C Programming

Prashant | Sun, 14 Jun, 2020 | 133

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 int2 Bytes-32,768 to 32,767
unsigned short or unsigned short int2 Bytes0 to 65,535

Here is the proof

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

unsigned short or unsigned short int stores 16 bits of data

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 int4 Bytes-2,147,483,648 to 2,147,483,647
unsigned int4 Bytes0 to 4,294,967,295

Here is the proof

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

unsigned int stores 32 bits of data

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.

0 comments
Leave a comment