ProgrammingHardProduct company OA

Assume a 64-bit LP64 ABI. What is printed?

Assume a 64-bit LP64 ABI. What is printed?
struct K { const int a; int b; };
printf("%zu", sizeof(struct K));
  1. A. 4
  2. B. 8
  3. C. 12
  4. D. 16

Correct answer: B. 8

The const qualifier affects how the compiler lets you use a, not its storage: a const int still occupies 4 bytes with 4-byte alignment, exactly like a plain int. a@0, b@4, total 8 bytes with no padding needed.

More C Programming questions

Exams that ask this topic