Can someone help me to understand behavior of sizeof()
operator?
#include <iostream>
using namespace std;
class A{
int first;
double last;
public:
A(int a)
{
cout << a << endl;
}
};
int main()
{
A a(3);
cout << sizeof(a) << endl;
return 0;
}
This code prints me size of a as 16 bytes. Size of class is calculated based on its members. So I have 4 bytes (int
) + 8 bytes (double
) = 12.
So why did I get 16 bytes?
When I comment out int
and double
members I get 1 byte.