Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

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 TypeVariable Size in ByteRange
int4 bytes-2147483648 to 2147483647
unsigned int4 bytes0 to 4294967295
signed int4 bytes-2147483648 to 2147483647
short int2 bytes-32768 to 32767
unsigned short int2 bytes0 to 65,535
signed short int2 bytes-32768 to 32767
long int4 bytes-2,147,483,648 to 2,147,483,647
signed long int4 bytessame as long int
unsigned long int4 bytes0 to 4,294,967,295
float4 bytes+/- 3.4e +/- 38 (~7 digits)
double8 bytes+/- 1.7e +/- 308 (~15 digits)
long double8 bytes+/- 1.7e +/- 308 (~15 digits)
wchar_t2 or 4 bytes1 wide character
char1 byte-127 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 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.

#include <iostream> // header
using namespace std; // including namespace std
int main()// main
   // output int size
   cout << "Size of int = " << sizeof(int) << endl; 
   // output char size
   cout << "Size of char = " << sizeof(char) << endl; 
   // output float size
   cout << "Size of float = " << sizeof(float) << endl; 
   // output double size
   cout << "Size of double = " << sizeof(double) << endl; 
   return 0;