C++ Programming

What are the differences between int, long, long long, and short? Between an unsigned and a signed type? Between a float and a double?

Short uses less memory and than int, long and long long. Minimum size of short and int is 16 bits, long has 32 bits, and long long has 64 bits. In C language the main difference is their size and range. Short is of 2 bytes and it’s value is from -32,768 to 32,767, int is of 4 bytes and its value is from -2,147,483,648 to 2,147,483,647, Long is of 4 bytes and it’s value is from -2,147,483,648 to 2,147,483,647 and long long is of 8 bytes and it’s value is from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

A signed variable can hold both positive and negative values. An unsigned variable can only hold positive integers. Both signed and unsigned can be applied to short, int, char and long. We can use cast to convert from signed to unsigned type and from unsigned to signed type. 

Float and double both are used to represent floating point numbers or decimal digits. Size of the float is 32 bits and for double it is 64 bits.  Float has 7 decimal digits precision whereas double has 15 digits precision.  

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments