This article covers Data Types in C++.
If you ever want to master C++, you’ll have to learn about it’s Data types in detail. It’s not enough to simply know that int
is for integers and so on. Each data type has it’s own specific size, it’s own limitations that you should know.
When it comes to advanced concepts like memory consumption and optimization, knowing and managing the size and limitations of the data types you’re using is important.
Data Types in C++
A compilation of the data types in C++.
Data Type | Size | Description |
---|---|---|
int | 4 Bytes | Stores Integers (numbers without a decimal part) |
float | 4 Bytes | For numbers with a decimal part. Able to store up-to 7 decimal digits. |
double | 8 Bytes | For numbers with a decimal part. Able to store up-to 15 decimal digits. |
boolean | 1 Byte | Only two possible values, True or False. |
char | 1 Byte | Stores a single character. |
string | N/A | A collection of characters. |
Strings are not a fundamental Data type (unlike the others in this list), but we decided to include it in the list. For the full explanation and examples of strings there is a separate article.
Complete list of Datatypes + Modifiers
Data types in C++ can easily be modified with certain keywords in order to change their size and range of supported values. These keywords are important because they determine the size of the data type. The larger the data type, the more memory it consumes.
A complete list of all variations of these modifiers is shown below.
Data Type | Size | Range |
---|---|---|
char | 1 Byte | Can be either unsigned or signed |
unsigned char | 1 Byte | 0 to 255 |
signed char | 1 Byte | -127 to 127 |
int | 4 Bytes | -2,147,483,648 to 2,147,483,647 |
unsigned int | 4 Bytes | 0 to 4294967295 |
signed int | 4 Bytes | -2147483648 to 2147483647 |
short int | 2 Bytes | -32768 to 32767 |
unsigned short int | 2 Bytes | 0 to 65,535 |
signed short int | 2 Bytes | -32768 to 32767 |
long int | 8 Bytes | -2,147,483,648 to 2,147,483,647 |
signed long int | 8 Bytes | -2,147,483,648 to 2,147,483,647 |
unsigned long int | 8 Bytes | 0 to 18,446,744,073,709,551,615 |
long long int | 8 Bytes | -(2^63) to (2^63)-1 |
unsigned long long int | 8 Bytes | 0 to 18,446,744,073,709,551,615 |
float | 4 Bytes | 3.4E +/- 38 (7 digits) |
double | 8 Bytes | 1.7E +/- 308 (15 digits) |
long double | 12 Bytes | 1.7E +/- 308 (15 digits) |
This marks the end of the C++ Data Types article. Any suggestions or contributions for CodersLegacy are more than welcome. Questions regarding the article content can be asked in the comments section below.