D

Dharmendra Sir • 3.53K Points
Extraordinary

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; 
}
  • (A) 4
  • (B) 8
  • (C) 16
  • (D) None of the above
  • Correct Answer - Option(A)
  • Views: 127
  • Filed under category C++

Explanation by: Dharmendra Sir
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.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics