C++ sizeof Operator
sizeof is a keyword and a compile-time operator that determines the size of given variable OR data-type, and returns result in bytes.
We can also use sizeof keyword to get size of classes, structures, unions and any other user defined data type.
Syntex:
sizeof ( data type)
to get the size of given datatype. like: sizeof(int)
or
sizeof (variable name)
Example program:
#include <iostream>
using namespace std;
int main() {
cout << "Size of char : " << sizeof(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 float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;
return 0;
}