Examples of data types in c++ Programming


data types are declarations for variables. This determines the type and size of data associated with variables. For example :

int age = 13;

All Contributions

C++ void :

The void keyword indicates an absence of data. It means "nothing" or "no value".

We will use void when we learn about functions and pointers. 

C++ bool :

The bool data type has one of two possible values: true or false.

Booleans are used in conditional statements and loops (which we will learn in later chapters).

For example :

bool cond = false;

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

For example :

wchar_t test = L'ם'  // storing Hebrew character;

C++ char:

Keyword char is used for characters.

Its size is 1 byte.

Characters in C++ are enclosed inside single quotes ' '.

For example:

 char test = 'h';

C++ float and double:

float and double are used to store floating-point numbers (decimals and exponentials).

The size of float is 4 bytes and the size of double is 8 bytes. Hence, double has two times the precision of float

For example:

float area = 64.74;
double volume = 134.64534;

As mentioned above, these two data types are also used for exponentials. For example :

double distance = 45E12    // 45E12 is equal to 45*10^12

total contributions (6)

New to examplegeek.com?

Join us