C++ Program to Size of all C Language Data Types

In this program, you will learn how to display the data type sizes using sizeof() operator. Data types specify how we enter data into our programs and what type of data we enter.

sizeof is a compile time unary operator which can be used to compute the size of its operand.



Source Code
#include <iostream>
using namespace std;

int main() {
  short s;
  int i;
  char c;
  float f;
  double d;
  long l;
  long double ld;

  cout<<"Size of short (in bytes) = " << sizeof(s) << endl;
  cout<<"Size of int = " << sizeof(i) << endl;
  cout<<"Size of char = " << sizeof(c) << endl;
  cout<<"Size of float = " << sizeof(f) << endl;
  cout<<"Size of double = " << sizeof(d) << endl;
  cout<<"Size of long = " << sizeof(l) << endl;
  cout<<"Size of long double= " << sizeof(ld);
  return 0;
}
Output
Size of short (in bytes) = 2
Size of int = 4
Size of char = 1
Size of float = 4
Size of double = 8
Size of long = 4
Size of long double= 16