Data Types in C++

Notes:

Data Types in C++ Programming Language:

Datatype:
As the name itself indicating, data type means type of data.

Note: While developing any software application; we come across different types of data and data values. We need to store and process them efficiently.

Ex: While developing
Game:
playerScore= 10; // playerScore is an integer type data
worldGravity =9.8; // worldGravity is a real type data
re-play=’y’; // re-play is a character type data

OR

Banking application:
accountNumber=10; // accountNumber is an integer type data
rateOfInterest=13.5; // rateOfInterest is a real type data
hasLoan=’y’; // hasLoan is a character type data

Types of data types:
To store and process different types of data and data values efficiently;
C++ provides 2 types of data types.
1. Primitive or basic or built-in
2. Non primitive or derived or composite

Primitive data types:
- There are 7 primitive data types provided by C++ language

1. int:
- is used to store and process integer numbers or whole numbers (i.e. numbers without decimal point)
Ex: 22, -44, 2017, etc.

Note: Numbers containing decimal point are called real numbers.

To store and process real numbers; C++ provides 2 different data types:
2. float:
- is used to store and process single precision real numbers (i.e. real numbers containing 6 to 7 digits after the decimal point )
Ex: 3.142, 9.8, 2.123456, 3.4E+38

3. double:
- is used to store and process double precision real numbers (i.e. real numbers containing 15 to 16 digits after the decimal point)
Ex: 3.142, 9.8, 2.1234567898765, 1.7E+308

Note: To store and process characters; C++ provides 2 different data types:

4. char:
- is used to store and process any symbol from the ASCII character set enclosed in between pair of single quotations
Ex: ‘A’, ‘9’, ‘$’, ’\n’, ‘\t’

5. wchar_t : widechar
- is used to store and process any symbol from the UNICODE character set enclosed in between pair of single quotations and prefixed with L character
Ex: L‘A’, L‘9’, L‘$’, L’\n’, L‘\t’

6. bool :
- is used to store and process Boolean values
Ex: true or false

7. void:
- indicates value less data type

Non -primitive data types:

1. array:
- is used to store and process list of data values

2. pointer:
- is used to store and process reference or address of another memory location

3. structure:
- is used to store and process a record of information

4. union:
- is used to store and process a record of information

5. class:
- is used to store and process an object information

6. enum:
- is used to store and process list of enumerated words

7. function or method:
- is used to perform a specific task