04 – C++ : Data Types



Variables play an important role in programming because they simply serve as containers which hold values. Data types are use when declaring a variable to specify the action that you want to perform, it may be a string, integer, character, boolean, double, floating point and etc.


See below the seven basic C++ data types:

Type Keyword
Boolean bool
Character char
Double floating point double
Integer int
Floating point float
Valueless void
Wide character wchar_t


The following are type modifiers that can be used to modify several of the basic data types that was shown above:

  • short
  • long
  • signed
  • unsigned


In the table below are the list of variable types. You will see how much memory would it takes to store the value in memory and also the minimum and maximum value to be stored.

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



This a procedure to generates the correct size of the data types on the computer. See it below.


This is the result when the code is perform.




Facebook Comments


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.