C++

C++ Data Types

C++ Data Types

This section gives detailed insights into data structures used in C++. In C++, data types are used for declarations of variables. This tells the compiler the type and size of data associated with variables. For example,

int income = 90000; 

Here income is a variable of type int and can store value in range for 2 bytes or 4 bytes depending upon the machine size. C++ has 7 fundamental system defined datatypes given in following table

Let us drill down each data type 

C++ int 🡪int denotes integers. Its size is machine dependent and is usually 4 bytes (value can be between -2147483648 to 2147483647). For e.g. 

int roll_no = 11;

C++ float and double 🡪 float and double are system's containers to store floating-point numbers which are usually decimals and exponentials. The size of float is generally 4 bytes and the size of double is 8 bytes. For e.g.

float percentage = 93.74;
double volumeOfSphere = 251.64534;

double distance = 3E21;

C++ char 🡪 Keyword char is used for storing characters. It can hold 1 byte. C++ characters are enclosed inside single quotes ' '. For e.g.

char gender = 'M';

C++ wchar_t 🡪 Wide character wchar_t is char data type with size 2 bytes instead of 1. It is used to represent non-ANSI (Unicode characters) that require more memory to represent them than a single char. IT is usually represented by appending L in in front of the value. C++11 revision also included char16_t and char32_t. For example,

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

C++ bool 🡪The bool data type is used for storuing variables having binary values i.e. True or False or On or OFF. IT finds application in conditional statements and loops. For example,

bool condFlag = true;

C++ void 🡪The void keyword indicates that given object is devoid of data. It means "no value". We use it in functions and pointers. Please note that void cannot be used to declare variables.

We can modify char, int and double data type using 4 modifiers i.e., signed unsigned, short and long. The following table gives list of internal datatypes with modifiers for C++.