Data types in C++

Data types are the declaration of any variables. These are the type of any variable and determine its size. int, float, double, long double, char, bool and string are the data types.

The following program shows data types. Size of these data types depends on the system.

#include<iostream>
#include<string>
using namespace std;
int main(){
int num1  = 5;
float num2 = 3.447476*3.254852;
long double num3 = 4.254589*8712697;
char ch = 'd';
bool boolValue = false;
string str = "My string";

cout<<"Integer number is "<<num1<<"\n";
cout<<"Floating point number is "<<num2<<"\n";
cout<<"Fractional number is "<<num3<<"\n";
cout<<"Single character is "<<ch<<"\n";
cout<<"Boolean value is "<<boolValue<<"\n";
cout<<"String is "<<str<<"\n";
cout<<"Size of float "<<sizeof(float)<<"\n";
cout<<"Size of int "<<sizeof(int);

return 0;
}

Output:

Integer number is 5
Floating point number is 11.221  
Fractional number is 3.70689e+007
Single character is d
Boolean value is 0
String is My string
Size of float 4
Size of int 4
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments