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;
}
β
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