C++ Data Types

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 TypeSize Description
int4 BytesStores Integers (numbers without a decimal part)
float4 BytesFor numbers with a decimal part. Able to store up-to 7 decimal digits.
double8 BytesFor numbers with a decimal part. Able to store up-to 15 decimal digits.
boolean1 ByteOnly two possible values, True or False.
char1 ByteStores a single character.
stringN/AA 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 TypeSizeRange
char1 ByteCan be either unsigned or signed
unsigned char1 Byte0 to 255
signed char1 Byte-127 to 127
int4 Bytes-2,147,483,648 to 2,147,483,647
unsigned int4 Bytes0 to 4294967295
signed int4 Bytes-2147483648 to 2147483647
short int2 Bytes-32768 to 32767
unsigned short int2 Bytes0 to 65,535
signed short int2 Bytes-32768 to 32767
long int8 Bytes-2,147,483,648 to 2,147,483,647
signed long int8 Bytes-2,147,483,648 to 2,147,483,647
unsigned long int8 Bytes0 to 18,446,744,073,709,551,615
long long int8 Bytes-(2^63) to (2^63)-1
unsigned long long int8 Bytes0 to 18,446,744,073,709,551,615
float4 Bytes3.4E +/- 38 (7 digits)
double8 Bytes1.7E +/- 308 (15 digits)
long double12 Bytes1.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.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments