Datatypes In C++
Datatypes in C++
Datatypes determines the type and size of the variable. the below image shows the different types of the datatypes in C++.
Integer (int):
As its name suggests this type stores integer values, its size is 2 or 4 bytes. depending upon the architecture of the computer.
Float (float) & Double (double):
Again the name suggests, this type store floating point values, the size of the float is 4 bytes, and the size of the double is 8 bytes.
Character (char):
this type stores the single character, they are enclosed in single quotes (' '). the size of the char is 1 byte.
apart from the above four datatypes two more datatypes boolean (bool), and wide character constant (wchar_t) were added in C++.
Wide Character constant (wchar_t):
Wide character wchar_t is similar to the char data type, except its size is 2 bytes instead of 1. It is used to represent characters that require more memory to represent them than a single char.
the wide character constant variable is declared as follows:
wchar_t var = L'A';
Boolean (bool):
this datatypes has two possible values true or false. they are mainly used in conditional statements and loops.
they are declared as follows:
bool flag = true;
Void (void):
the type void was introduce in ANSI C. their are mainly 2 use of void:
- to specify the return type of the function.
- to indicate an empty argument list to a function.
Data Modifiers:
we can further modify some of the primitive datatypes to increase the functionality of the datatypes.
- signed
- unsigned
- short
- long
we can only modify int, float, char with the above modifiers.
Comments
Post a Comment
if you have any doubts, let me know