Sunday 28 December 2014

Cpp Program to get the sizes of all Datatypes

This is a simple Cpp program which tells us the size of the various datatypes we use.
here we use 'sizeof ' operator to get the sizes of all datatypes.


PROGRAM :
#include <iostream>

using namespace std;

int main()
{
    cout << "A cpp Program to get the size of all datatypes \n\n";

    cout << "Size of char : " << sizeof(char) << endl ;
    cout << "Size of signed char : " << sizeof(signed char) << endl;
    cout << "Size of unsigned char : " << sizeof(unsigned char) << endl;
    cout << "Size of int : " << sizeof(int) << endl;
    cout << "Size of short int : " << sizeof(short int) << endl;
    cout << "Size of long int : " << sizeof(long int) << endl;
    cout << "Size of signed int : " << sizeof(signed int) << endl;
    cout << "Size of unsigned int : " << sizeof(unsigned int) << endl;
    cout << "Size of signed long int : " << sizeof(signed long int) << endl;
    cout << "Size of unsigned long int : " << sizeof(unsigned long int) << endl;
    cout << "Size of float : " << sizeof(float) << endl;
    cout << "Size of double : " << sizeof(double) << endl;
    cout << "Size of long double : " << sizeof(long double) << endl;
    cout << "Size of boolean : " << sizeof(bool);


    return 0;
}
OUTPUT :

Cpp - Datatype Sizes