Q. Suppose the integers take 4 bytes, what is the output of the following code?
Code:
#include<iostream>
using namespace std;
class MyClass
{
static int a;
int b;
};
int MyClass::a;
int main()
{
cout << sizeof(MyClass);
return 0;
}
β
Correct Answer: (A)
4
Explanation: Static data members do not contribute to the size of an object. So, “a” is not considered in the size of “MyClass”. By the way, not all functions (static and non-static) contribute to the size.