The compiler aligns variables to the maximum size for quick access. Variables А and B in class A will be aligned to 8 bytes (char takes 1 byte and int - 4 bytes) according to maximum variable - double C (8 bytes). Therefore, sizeof(A) is equal to 16 bytes.
Variable A in class B will be aligned according to C. Same will be done to with variable B since compiler handles variables in order of their declaration. Therefore, sizeof(B) equals 24 bytes.
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати