πŸ“Š C++
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
πŸ’¬ Discuss
βœ… 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.

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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
174
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Dharmendra Sir
Publisher
πŸ“ˆ
88%
Success Rate