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++.

The primitive datatypes also known as Built-in Datatypes are the basic datatypes,

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:
  1. to specify the return type of the function.
  2. 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.
  1. signed
  2. unsigned
  3. short
  4. long
we can only modify int, float, char with the above modifiers.

Size and range of C++ basic datatypes

Derived datatypes:

this datatypes are derived from the fundamental datatypes for example:- array, pointers, function types, etc.

Comments

Popular posts from this blog

Structure Of C++ Program