short Data Type

 

We noted that the integer has four bytes in memory. So if we have to store a small integer like 5, 10 or 20 it will occupy four bytes. The C provides another data type for storing small whole numbers which is called short. The size of short is two bytes and it can store numbers in range of -32768 to 32767. So if we are going to use a variable for which we know that it will not increase from 32767, for example the age of different people, then we use the data type short for age. We can write the above sample program by using short instead of int.

 

#include <iostream.h>

main()

{

            short x;

            short y;

            short z;

            x = 5;

            y = 10;

            z = x + y;

            cout << “x = “;

            cout << x;

            cout << “ y=“;

            cout << y;

            cout << “ z = x + y = “;

            cout << z;

}

 

 

x = 5 y = 10 z = x + y = 15

 

 

 

Previous

 

 

TOC

 

 

Next