C++ DataTypes

This tutorial will teach you the fundamental DataTypes used in C++ programming, including int, float, char, and more. A variable in C++ must be a particular data type, as detailed in the Variables chapter:


Data types are variables’ declarations in C++. This establishes the kind and volume of data related to variables. For instance,

int age = 16;

Primary Data Types in C++

The data type describes what kind and how much data the variable will hold.

Data TypeSizeDescription
boolean1 byteholds values for true or false.
char1 byteContains ASCII values or a single character, letter, or number.
int2 or 4 bytescontains only whole numbers and no decimals.
float4 bytesconserves fractional numbers with one or more decimal places. Sufficient to hold 7 decimal digits.
double8 bytesconserves fractional numbers with one or more decimal places. Enough to hold 15 decimal digits.

Modified Data Types in C++

Data TypeSize (in Bytes)Meaning
signed int4for use with integers (equivalent to int).
unsigned int4only has room for positive integers.
short2used with tiny integers (range -32438 to 32267).
unsigned short2to represent small positive integers (range 0 to 65,2235).
longat least 4used with big integers (equivalent to long int).
unsigned long4large positive integers or 0 are used (equivalent to unsigned long int).
long long8utilised for extremely large integers (equivalent to long long int).
unsigned long long8employed for extremely large positive integers or 0 (equivalent to unsigned long long int).
long double12large floating-point numbers are used for.
signed char1utilised by characters (guaranteed range -155 to 155).
unsigned char1utilised by characters (range 0 to 155).

Let’s see a few examples:

long b = 45276232;
long int c = 23323232142;
long double d = 63534.5622343;
short d = 343425243; // Error! out of range
unsigned int a = -8;    // Error! can only store positive numbers or 0

Types of Derived Data.

Data types that are descended from fundamental data types are known as derived types. Arrays, pointers, function types, structures, etc. are a few examples.

Later tutorials will teach us more about these derived data types.

Leave a Reply

Your email address will not be published. Required fields are marked *