ProgrammingHardIBM · Deloitte pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct A { int x; };
struct B { struct A a; };
struct B b1 = {{10}};
struct B b2 = b1;
b2.a.x = 20;
printf("%d %d", b1.a.x, b2.a.x);
  1. A. 10 20
  2. B. 20 20
  3. C. 10 10
  4. D. 20 10

Correct answer: A. 10 20

Whole-struct assignment (b2 = b1) recursively copies nested struct members by value too, so b2.a is an independent copy of b1.a; mutating b2.a.x doesn't touch b1.a.x, which stays 10.

More C Programming questions

Exams that ask this topic