♦ C++ Data Types
♣ About C++ Data Types
Data Types are fundamentally classified based on the amount of memory for each Data Type.Each Data Type has the capability of holding a different type of entity.
Some common occurring Data Types in C++ are int, float, and char.
Custom Data Types can also be created in C++, that will be covered in OOP(Object Oriented Programming) section.
♣ C++ Data Types
Data Types in C++ are majorly classified as.- Primitive
- Complex
- User Defined
♣ Primitive Data Types in C++
Primitive Data Types are in-built Data Types which can be defined in one-line.This include:-
- int
- float
- double
- bool
- char
Data Type | Size(in Bytes) | Range | |
---|---|---|---|
int | 4 | -2,147,483,648 to 2,147,483,647 | |
float | 4 | ||
double | 8 | ||
bool | 1/8, i.e, 1 bit | 0(false) or 1(true) | |
char | 1 | 128 | keyboard characters + 128 other characters |
♣ Modified Primitive Data Types in C++
There also exist Other versions of Primitive Data Types.Below is a tabular explanation of DataTypes
Data Type | Size(in Bytes) | Range |
---|---|---|
short int | 2 | -32,768 to 32,767 |
unsigned short int | 2 | 0 to 65,535 |
unsigned int | 4 | 0 to 4,294,967,295 |
long int | 4 | -2,147,483,648 to 2,147,483,647 |
unsigned long int | 4 | 0 to 4,294,967,295 |
long long int | 8 | -(2^63) to (2^63)-1 |
unsigned long long int | 8 | 0 to 18,446,744,073,709,551,615 |
signed char | 1 | -128 to 127 |
unsigned char | 1 | 0 to 255 |
long double | 12 | |
wchar_t | 2 or4 | 1 wide character |
♣ Complex Data Types
Complex Data Types add a little more complexity while defining, but are also powerful.This include:-
- array
- function
- pointer
- reference
♣ User-Defined Data Types
User-Defined Data Types are custom modified Data Type versions of the combination of Primitive and Complex Data Types.This include:-
- class
- structure
- union
- enumeration
- typedef