Facebook Page Twitter Page LinkedIn Page
× C++ Tutorial C++ Advanced C++ Resources

One of the most important parts of learning any programming language is to understand what are the available data types, and how data is stored, accessed and manipulated in that language. Based on the data type of a variable, the operating system allocates memory to the variable and decides what can be stored in the reserved memory.

There are three types of data types in C++ which are categorized below:

CategoryData Types
Basic Data Typeinteger, character, boolean, floating point, double floating point, void, wide character, etc.
Derived Data Typearray, pointer, function, reference, etc.
User Defined Data Typeclass, structure, union, enum, typedef, etc.

The below table describes basic data types of C++ in detail:

CategoryData Types
Floating Pointfloat
Double Floating Pointdouble
The Void Typevoid
Wide characterwchar_t

There are several types of modifier which can be used to modify the data types in C++.

  • signed
  • unsigned
  • short
  • long

The below table describes the variable type, memory size, and maximum and minimum value which can be stored in the variable.

CategoryMemory SizeRange
char1 byte-128 to 127
unsigned char1 byte0 to 255
signed char1 byte-127 to 127
short int 2 byte -32,768 to 32,767
unsigned short int 2 byte 0 to 65,535
signed short int 2 byte -32,768 to 32,767
int4 byte-2,147,483,648 to 2,147,483,647
unsigned int4 byte0 to 4,294,967,295
signed int4 byte-2,147,483,648 to 2,147,483,647
long int 8 byte -2,147,483,648 to 2,147,483,647
unsigned long int 8 byte 0 to 4,294,967,295
signed long int 8 byte -2,147,483,648 to 2,147,483,647
long long int 8 byte -(2^63) to (2^63)-1
unsigned long long int 8 byte 0 to 18,446,744,073,709,551,615
float 4 byte
double 8 byte
long double 12 byte
boolean 1 byte
void 1 byte
wchar_t 2 or 4 byte 1 wide character

sizeof() function

The memory size of a data type might be different as shown in the above table, depending upon the compiler. To find out the size of a data type, sizeof() function can be used.

#include <iostream>
using namespace std;
int main (){
   cout<<"Size of char: "<<sizeof(char)<<"\n"; 
   cout<<"Size of short int: "<<sizeof(short int)<<"\n";
   cout<<"Size of int: "<<sizeof(int)<<"\n";
   cout<<"Size of long int: "<<sizeof(long int)<<"\n";
   cout<<"Size of float: "<<sizeof(float)<<"\n";
   cout<<"Size of double: "<<sizeof(double)<<"\n";
   cout<<"Size of boolean: "<<sizeof(bool)<<"\n";
   cout<<"Size of void: "<<sizeof(void)<<"\n";
   cout<<"Size of wide character: "<<sizeof(wchar_t)<<"\n";   
   return 0;

The output of the above code will be:

Size of char: 1
Size of short int: 2
Size of int: 4
Size of long int: 8
Size of float: 4
Size of double: 8
Size of boolean: 1
Size of void: 1
Size of wide character: 4