C++ Tutorials

C++ Tutorials

C++ provides a compiler-time unary operator called sizeof that can be used to compute the size of any object.

The expression such as:

  • sizeof object
  • sizeof(type name)

Example :

using namespace std;
int main()

    cout<<"size of int in byte : "<< sizeof(int)<<"\n";
    cout<<"size of char in byte : "<< sizeof(char)<<"\n";
    cout<<"size of float in byte :"<< sizeof(float)<<"\n";

    return 0;

Output :

 size of int in byte :  4
 size of char in byte 1
 size of float in byte 4