I was looking at a small program -
#include<iostream>
class A
{
bool a;
bool c;
};
int main()
{
std::cout << sizeof(A) << std::endl;
return 0;
}
Here, it shows the size of class A as 2 bytes. But, if I add another integer data member to this class as -
class A
{
int b;
bool a;
bool c;
};
Now, it shows the size of class A as 8 bytes instead of 6 bytes. Why compiler does padding in second case & why not in first case?