Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "short int" and "int" in C?

Tags:

c

types

How is short int (or short) and int different in C? They have the same size and range. If they are essentially the same, what is the use of having two data types?

like image 772
Kanwaljeet Singh Avatar asked Sep 05 '12 10:09

Kanwaljeet Singh


People also ask

What does short int mean in C?

short int. signed short. signed short int. Short signed integer type. Capable of containing at least the [−32,767, +32,767] range.

Is Short same as int?

In C++ (and C), short , short int , and int short are different names for the same type. This type is guaranteed to have a range of at least -32,767..

What is the difference between short and short int?

There is no difference.

Is Short bigger than int?

short datatype is the variable range is more than byte but less than int and it also requires more memory than byte but less memory in comparison to int. The compiler automatically promotes the short variables to type int, if they are used in an expression and the value exceeds their range.


2 Answers

They may have the same size, but it is guaranteed that int is equal to or bigger than short int.

like image 71
MByD Avatar answered Oct 11 '22 11:10

MByD


In theory/by the C standard, they could be of any size as long as 16 bit <= short <= int.

In the real world, this is how the sizes are implemented.

CPU             short   int 8 bit           16      16 16 bit          16      16 32 bit          16      32 64 bit          16      32 
like image 39
Lundin Avatar answered Oct 11 '22 11:10

Lundin