Data Types in CPP (C Plus Plus)

Data Types in CPP (C Plus Plus)

What is Data Types?

All variables use data-type during declaration to restrict the type of data to be stored. Some memory occupied by the compiler that variable based on the data-type with which it is declared. Every data type has a different amount of memory.

C++ Data Types chart with size and range.

Variable Type Variable Size in Byte Range
int 4 bytes -2147483648 to 2147483647
unsigned int 4 bytes 0 to 4294967295
signed int 4 bytes -2147483648 to 2147483647
short int 2 bytes -32768 to 32767
unsigned short int 2 bytes 0 to 65,535
signed short int 2 bytes -32768 to 32767
long int 4 bytes -2,147,483,648 to 2,147,483,647
signed long int 4 bytes same as long int
unsigned long int 4 bytes 0 to 4,294,967,295
float 4 bytes +/- 3.4e +/- 38 (~7 digits)
double 8 bytes +/- 1.7e +/- 308 (~15 digits)
long double 8 bytes +/- 1.7e +/- 308 (~15 digits)
wchar_t 2 or 4 bytes 1 wide character
char 1 byte -127 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -127 to 127

The size of the variables might be different from those shown in the above table, depending on the PC and the PC you are using. Following is the example, which will produce the correct size of various data types on your system. we can use sizeof(data type) for finding size in coding.

Output

Size of int = 4

Size of char = 1

Size of float = 4
Size of double = 8

Prof. Fazal Rehman Shamil
Latest posts by Prof. Fazal Rehman Shamil (see all)

    Buy advertisement space on T4Tutorials

    For more details email [email protected]