& operator and sizeof in C++

 

#include <iostream>

int main()
{
   double d_var = 90;
   int var = 5;
   char c_var = 'a';
   cout << &var << " stored value " << var << " " << sizeof(var) << endl;
   cout << c_var << " stored value " << c_var << " " << sizeof(c_var) << endl;
   cout << &d_var << " stored value "  << d_var  << " " << sizeof(d_var) << endl;
  
   cout << "Size of short int : " << sizeof(short int) << endl;
   cout << "Size of long int : " << sizeof(long 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 wchar_t : " << sizeof(wchar_t) <<endl;

   return 0;
}


Output:

1
2
3
4
5
6
7
8
9
0xfff4fcc8 stored value 5 4
a stored value a 1
0xfff4fcc0 stored value 90 8
Size of short int : 2
Size of long int : 4
Size of signed long int : 4
Size of unsigned long int : 4
Size of float : 4
Size of wchar_t : 4




Comments