Cpp - Write program to get the size of basic data types

Requirements

Write program to get the size of basic data types

Hint

The sizeof operator can be used to determine the number of bytes occupied in memory for a certain type.

For example, sizeof(short) is equivalent to 2.

Demo

#include <iostream> 
using namespace std; 
int main() //from w w  w  .  j  a v a 2s .  co  m
{ 

   cout << "\nSize of Fundamental Types\n" 
        << "  Type           Number of Bytes\n" 
        << "----------------------------------" << endl; 
   cout << "  char:           " << sizeof(char) << endl; 
   cout << "  short:          " << sizeof(short)<< endl; 
   cout << "  int:            " << sizeof(int)  << endl; 
   cout << "  long:           " << sizeof(long) << endl; 
   cout << "  float:          " << sizeof(float)<< endl; 
   cout << "  double:         " << sizeof(double)<<endl; 
   cout << "  long double:    " << sizeof(long double) 
         << endl; 

   return 0; 
}

Result