Q. Suppose the size of an integer is 4 bytes, what is the output of the following code?

Code:
#include<iostream> 

using namespace std; 
  
class A { 
    int arr[10];      
}; 
  
class B: public A { }; 
  
class C: public A { }; 
  
class D: public B, public C {}; 
  
int main(void) 
{  
  cout << sizeof(D); 
  return 0; 
}
  • (A) 4
  • (B) 40
  • (C) 80
  • (D) 160
πŸ’¬ Discuss
βœ… Correct Answer: (C) 80
Explanation: Since B and C inherit from the parent class A, two copies of the parent class are present in class D, so 2*(4*10)=80 bytes
Explanation by: Dharmendra Sir
Since B and C inherit from the parent class A, two copies of the parent class are present in class D, so 2*(4*10)=80 bytes

πŸ’¬ Discussion


πŸ“Š Question Analytics

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