Home Segments Index Top Previous Next

55: Sidetrip

If you are curious about how much memory your C++ implementation allocates for the various data types, you can compile and execute the following program, which uses the sizeof operator to determine data-type size:

#include   
main ( ) { 
  cout << "Data Type    Bytes" << endl 
       << "char         " << sizeof(char) << endl 
       << "short        " << sizeof(short) << endl 
       << "int          " << sizeof(int) << endl 
       << "long         " << sizeof(long) << endl 
       << "float        " << sizeof(float) << endl 
       << "double       " << sizeof(double) << endl 
       << "long double  " << sizeof(long double) << endl; 
}