C++ Data Types-int, float, char, double, bool
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 Type | Size in Byte |
int | 2 bytes |
short | 2 bytes |
unsigned int | 2 bytes |
long | 4 bytes |
unsigned long | 4 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 Type | Meaning | Size | Description |
Int | Integer | 2 or 4 bytes | Stores numbers without decimal. |
Char | Character | 1 byte | Stores single characters. |
Double | Double Floating-point | 8 bytes | store fractional numbers, sufficient for 15 decimal digits. |
Float | Floating-point | 4 bytes | Store fractional numbers, sufficient for 7 decimal digits. |
Bool | Boolean | 1 byte | Store values like true and false. |
void | Empty | 0 | specifies that the function doesn’t return a value |
Wchar _ t | Wide character | 2 | used for Unicode UTF-16 strings |
Leave a Reply