Home | Computer | C++ Data Types-int, float, char, double, bool

C++ Data Types-int, float, char, double, bool

August 20, 2022

C++ has many data types like int, char, float, bool, etc.

Integer data types in C++

Integer data is a numeric value with no decimal point or fraction. It includes both positive and negative values. The minus sign – is used to indicate a negative value. If no sign is used, the value is positive by default. E.g. 10,470 and 40.

Types of integers

C++ provides different types of integer data.

           Data TypeSize in Byte
int2 bytes
short2 bytes
unsigned int2 bytes
long4 bytes
unsigned long4 bytes

Syntax of integers

int salary = 53000;

       cout << salary;            

Float data type

The float data type is used to store fractional data. It provides an accuracy of 6 decimal places.

Syntax of float

float temperature = 15.66;

cout<<temperature;

Char data type

Char data type is used to store character value. It takes 1 byte in memory. It is used to represent a letter, number or punctuation mark and a few other symbols.

Syntax of char data

char ch1, ch2, sum;

ch1 = ‘A’;

char =’B’;

cout <<“Characters are:”<<ch1<<ch2;

Bool data type  

The bool data type is used to value whether it is true or false.

Syntax of bool  

bool myboolean = true;

Data TypeMeaningSizeDescription
IntInteger2 or 4 bytesStores numbers without decimal.
CharCharacter1 byteStores single characters.
DoubleDouble Floating-point8 bytesstore fractional numbers, sufficient for 15 decimal digits.
FloatFloating-point  4 bytesStore fractional numbers, sufficient for 7 decimal digits.
BoolBoolean1 byteStore values like true and false.
voidEmpty0 specifies that the function doesn’t return a value
Wchar _ tWide character2used for Unicode UTF-16 strings