Home   |   About   |   Terms   |   Contact    
Read & Learn
 

sizeof Operator in C++

C++

☯ All C++ Articles     ☯ All Articles


A new product.





Popular Google Pages:




This article is regarding sizeof Operator in C++.
Last updated on: .
Choose your Language: English     Bengali



◕ Let a simple program:
#include <iostream>
#include <climits>

using namespace std;
int main()
{
int man = 2;

cout << "int is a Type. The size of this Type is " << sizeof (int) << " Bytes." << endl;
cout << "man is a Variable. The size of this Variable is " << sizeof (int) << " Bytes." << endl;
return 0;
}



◕ This above program will produce the following answer:

int is a Type. The size of this Type is 4 Bytes.
int is a Variable. The size of this Variable is 4 Bytes.



◕ In the above example:

The sizeof is an Operator in the C++. We can say an Operator is a Built-in-Language Element that operates on one or more items. Such as addition ( + ), subtraction ( - ), multiplication ( x ) and divide ( / ).

When we use the sizeof operates then we have to include the climits header file.
The sizeof operator returns the size of a Type or size of a Variable in Bytes.



◕ Please note that:

- When we use sizeof operator to find the size of a Type such as int, then we enclose the Type in parentheses.

- And when we use sizeof operator to find the size of a Variable such as man, then parentheses is optional.

- The size of a Type may vary in different system due climits header file. Because different manufacturers make it differently.





Popular Google Pages:



Top of the page

Amazon & Flipkart Special Products

   


Top of the page