sizeof operator in C++

sizeof operator in C++ is an unary operator which can be used to find the size of the data-type or expression or a variable.

It returns the size of the memory allocated (in Bytes) by the compiler. Lets say, we want to find the size of the memory allocated to the data-type int. We can find it by using sizeof operator as shown in the below code:

#include<iostream.h>
#include<conio.h>
void main()
{
     clrscr();
     int sizeOfInt;
     sizeOfInt = sizeof(int);
     cout << sizeOfInt << " Bytes";
     getch();
}

Output:

2 Bytes

As you can see, the above code calculated the size of int data type and displayed the result in C++.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *