A

Admin • 833.24K Points
Coach

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
  • Correct Answer - Option(C)
  • Views: 34
  • Filed under category C++
  • Hashtags:

Explanation by: Admin

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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.