All variables use data-type during declaration to confine the type of information to be put away. Thusly, we can say that data types are utilized to tell the variables the type of data it can put away. At whatever point a variable is characterized in C++, the compiler assigns some memory for that variable based on the data-type with which it is announced. Each data type requires a different measure of memory.
- Primitive Data Type
- Derived Data Type
- User-Defined Data Type
Primitive Data Types in C++: These data types are implicit or predefined data types and can be utilized straight by the client to pronounce variables. example: int, char , float, bool and so on . Primitive data types accessible in C++ are:
- Integer
- Character
- Boolean
- Floating Point
- Double Floating Point
- Valueless or Void
- Wide Character
Derived Data Types in C++: The datatypes that are gotten from the primitive or underlying data types are referred to as Derived Data Types. These can be of four kinds to be specific:
- Function
- Array data type
- Pointer data type
- Reference data type
Abstract or User-Defined Data Types in C++: These data types are characterized by client or user itself. Like, characterizing a class in C++ or a structure. C++ gives the accompanying user-defined data types:
- Class
- Structure
- Union
- Enumeration
- Typedef defined Data Type
Datatype Modifiers in C++
As the name suggests, datatype modifiers are utilized with the built-in data types to alter the length of information that a specific data type can hold.
- Signed data type
- Unsigned data type
- Short data type
- Long data type
Beneath table sums up the adjusted size and scope of built-in datatypes when joined with the type modifiers:
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 |
int | 4 | -2,147,483,648 to 2,147,483,647 |
long int | 4 | -2,147,483,648 to 2,147,483,647 |
unsigned long int | 8 | 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 |
float | 4 | |
double | 8 | |
long double | 12 | |
wchar_t | 2 or 4 | 1 wide character |
#include <iostream>using namespace std;int main() {cout << "Size of char : " << sizeof(char) << endl;cout << "Size of int : " << sizeof(int) << endl;cout << "Size of short int : " << sizeof(short int) << endl;cout << "Size of long int : " << sizeof(long int) << endl;cout << "Size of float : " << sizeof(float) << endl;cout << "Size of double : " << sizeof(double) << endl;cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;return 0;}
Output:
Size of char : 1 byteSize of int : 4 bytesSize of short int : 2 bytesSize of long int : 8 bytesSize of float : 4 bytesSize of double : 8 bytesSize of wchar_t : 4 bytes
0 Comments
🙏🙏please don't enter any spam links on the comment box.....