Check The Programming Section
There are four (4) modifiers preceding the basic data types (except void). These modifiers are used to alter the meaning of basic data types, to fit in various situations more accurately. The list of modifiers are as follows:
signed
unsigned
short
long
All four modifiers are applicable with integer data type. By default integer is represented as signed integer. A signed integer can represent both positive and negative numbers. So
signed int num;
is same as
int num;
The higher order bit (after converting a decimal number to binary) of an integer is represented as sign flag bit. If the sign flag is set to 1, then the number is negative and it is zero (0) for a positive number. So for an unsigned int, if the value is set to -1, then the number becomes 4294967295 (in a 64-bit system). The maximum value an unsigned int can have. Consider the following program:
#include<iostream>
#include<limits>
using namespace std;
int main(){
unsigned int num =-1;
cout<<UINT_MAX<<" "<<num;
}
The limits header file has defined various macros to get the maximum and minimum value that a data type can holds. The UINT_MAX is a macro gives the maximum value that a unsigned int can hold, which is 4294967295 (in a 64-bit system).
short and long modifies also allowed to be prefixed with int type and unsigned and signed modifies can also combined with these two modifiers. As follows:
unsigned short int num;
signed short int num;
unsigned long int num;
signed long int num;
Note: When type modifiers is used by iteself, means modifiers did not preceded the basic data type, then compiler consider the type as int. Thus the following sets of type specifier is equivalent.
Out of these 4 modifiers, only signed and unsigned can be applied with char basic data type. The default modifiers of char is unsigned and the most important use of signed is to modify the char. So the statement
unsigned char ch;
is same as
char ch;
Only the long is applicable with double floating-point basic data type and the required size in bits is 80 equal to 10 bytes. The long double floating-point supports upto 10th decimal place. Declaring a long double type
long double val;
In the below Table, we have shown all the valid data types combinatios, along with their minimal ranges and approximate bit widths. Remember, the table shows the minimum range that these types will have as specified by Standard C/C++, not their typical range.