C++ Program To Find Size Of Data Types
Write C++ Program to Print Size of Various Data types
// Write C++ program to demonstrate use of data types (signed int, int, signed float, float, char, double , long double, Boolean, long int)
#include<iostream>
using namespace std;
int main()
{
char charType;
signed int signedIntType;
int intType;
long int longIntType;
float floatType;
double doubleType;
long double longDoubleType;
// sizeof evaluates the size of a variable
cout << "Size of char \t\t: "<< sizeof(charType) <<" byte";
cout << "\nSize of signed integer \t: " <<sizeof(signedIntType)<<" byte";
cout << "\nSize of int \t\t: "<<sizeof(intType) << " bytes";
cout << "\nSize of long int \t: " <<sizeof(longIntType) <<" bytes";
cout << "\nSize of float \t\t: " << sizeof(floatType) <<" bytes";
cout << "\nSize of double \t\t: " << sizeof(doubleType)<< " bytes" ;
cout << "\nSize of long double \t: "<< sizeof(longDoubleType)<<" bytes";
return 0;
}
Output:
Size of char : 1 byte
Size of signed integer : 4 byte
Size of int : 4 bytes
Size of long int : 4 bytes
Size of float : 4 bytes
Size of double : 8 bytes
Size of long double : 16 byte