Data types in C and C++ defines how memory are used in a program. Using data types we can store information/data in the memory.In every program we will make use of English characters , numbers(integers and real numbers ) and some other special symbols like |,!,#,&,*,etc.These characters , numbers and symbols are used and stored using data types and variables.English alphabet are found in the English keyboard but,what about Hindi or Japanese Hiragana or Russian alphabet which are not found in the keyboard.To make the computer enable the use of all kinds of letter which are found and not found in the specific language keyboard data type is classified into different types.There can be however a two major classification of data types in C and C++.They are given below.
i)Built-in data types and
ii)User-defined data types.
In Chapter 1 we will discuss the built-in data types.
Built-in data types
Built-in data types are those data types which are hard coded in the compiler and so the compiler can understand them.You cannot change what they represent.They are inherited from the C language so,if you are familiar with C you already know what built-in data type of C++ is.But,those who does not know C,worry not! we will discuss them in detail in this chapter.
Built-in data types can be divided into seven different types.Each of this type can represent various data in your program.How to use these type is not shown here,you can visit the specific post of each type to learn how to use them in your program.The seven types and the keyword(visit this link to know what is keyword Some terms:Variables , Identifier , Keyword , Operators , Operands,literals.) used to implement them is shown below.
i)Integral types:This type can represent integers value in your program.And the keyword included under this type are :int,long int and long long int.
ii)Floating point type:This type can represent real numbers,meaning numbers with decimal point.The keyword included are float ,double and long double.
iii)Character type:This type can represent characters -a singe letter,and the keyword included under this type is char.
iv)String:This type can represent a text or a sentence.The keyword used is string.
v)Wide character:It can represent a Unicode characters-a letters not belonging to English Alphabets,so Japanese letters or Hindi or Russian alphabets,etc. are included under this type.The keyword use is wchar_t.
vi)Wide string:It can represent a Unicode strings ,for instance a Russian word or Hindi sentence,etc.The keyword use is wstring.
vii)Bool:It can represent only two values ‘True’ or ‘false’ and true is denoted by 1 and false by 0.
The seven types given here can be sub-divided into 12 types .Note all the seven types will occupy different sizes and the size they occupy depends on the machine and compiler you are using,the table below shows the different sub-data types with their meaning and the minimum size they occupy in memory.
|Data type||Meaning||minimum size|
|short int or short||Can represent short integer|
(integer of smaller size)
|Int||Integer(large integer)||4 bytes|
|long int||long integer(larger integer)||4 bytes|
|long long||they can represent largest integer||8 bytes|
|Float||Can represent real number||4 bytes|
|double||Can represent real number with larger size||8 bytes|
|long double||Can represent real number with largest size||12 bytes|
|Char||Can represent characters||1 bytes|
|wchar_t||Can represent unicode characters||2 bytes(in Windows),4 bytes(in Linux)|
|char16_t||Can represent unicode characters||2 bytes|
|char32_t||Can represent unicode characters||4 bytes|
|bool||Can represent truth value:true and false||1 byte|
|string||Can represent a collection of characters(words or sentence or text lines)||4 bytes|
|wstring||Can represent unicode characters string||4 bytes|
The integer types:short,int,long int,long long and the char type can be further sub-divided into two types using a specifier known as signed and unsigned keyword.More about these types and their differences will be discussed in detail in another post.
Earn money($$$) from your website-Join Now!
Size of different data types
Size is one of the properties of any data types in C and C++ and it plays a significant role for any data type while allocating a storage in the memory.Greater is the size of a data type larger is the memory it can allocate and larger is the range of values that type can represent.The program below uses the sizeof( ) operator to obtain the size of all the data types in byte.
*Note::If you have trouble understanding the program below then check out The First Program ,first and then come back.
using namespace std ;
int main( )
cout<< “Size of short int ” << sizeof(short) << endl ;
cout<< “Size of int ” << sizeof(int) << endl ;
cout<< “Size of long int ” << sizeof(long int) << endl ;
cout<< “Size of long long ” << sizeof(long long) << endl ;
cout<< “Size of char ” << sizeof(char) << endl ;
cout<< “Size of wchar_t ” << sizeof(wchar_t) << endl ;
cout<< “Size of char16_t ” << sizeof(char16_t) << endl ;
cout<< “Size of char32_t ” << sizeof(char32_t) << endl ;
cout<< “Size of float ” << sizeof(float) << endl ;
cout<< “Size of double ” << sizeof(double) << endl ;
cout<< “Size of long double ” << sizeof(long double) << endl ;
cout<< “Size of bool ” << sizeof(bool) << endl ;
cout<< “Size of string ” << sizeof(string) << endl ;
cout<< “Size of wstring ” << sizeof(wstring) << endl ;
return 0 ;
You can run the above program and see for yourself the size of different data types in C and C++.Note the size printed out here is for your particular machine and compiler,another machine can give different values.