Every programming language requires, programmers to declare the variables, to store values and manipulate them.
Variables are nothing but reserved spaces in the memory. The variables can store different types of data like numbers, characters, decimals, or even words and sentences.
The type of data that a variable will hold is determined by the data type with which it is declared.
Here, a is a variable that will hold the integer values as it is declared with int keyword and int here is the data type.
There are two types of data types in C++:
- Primitive Data Types
- Non – Primitive Data Types
Primitive Data Types:
The built-in data types in C++, are known as the Primitive Data Types.
Following are the 7 basic data types in C++.
|Double floating point||double|
The memory occupied and the range of each of these data types s as follows:
|Data Type||Memory Occupied||Range|
|char||1byte||-127 to 127 or 0 to 255|
|unsigned char||1byte||0 to 255|
|signed char||1byte||-127 to 127|
|int||4bytes||-2147483648 to 2147483647|
|unsigned int||4bytes||0 to 4294967295|
|signed int||4bytes||-2147483648 to 2147483647|
|short int||2bytes||-32768 to 32767|
|unsigned short int||Range||0 to 65,535|
|signed short int||Range||-32768 to 32767|
|long int||4bytes||-2,147,483,647 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)|
|2 or 4 bytes||1 wide character|
Non – Primitive Data Types:
Non – Primitive Data Types are the ones that are also known as the user-defined data types as they can hold the data as per the choice of the programmer. We will read about these Non – Primitive Data Types in detail later on.