Select the correct answer for a 32-bit OS (automatic alignment is not defined):

class A
{
       char A;
       int B;
       double C;
};
class B
{
      char A;
      double C;
      int B;
};
Explanation
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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes