This is printing 16 and 4 as the answer but it should be printing as 8 and 4 because both a
and b
are integer type variables. So can we think this as the compiler stores the address of the variable a
in a separate variable while copying to b
that is why it is resulting in 4 + 4 + 8 = 16
? If not then what is it?
#include <iostream>
using namespace std;
class C {
public:
int a = 45;
int &b = a;
};
int main() {
C ob1;
cout << sizeof(ob1) << endl;
cout << sizeof(ob1.b);
return 0;
}