ProgrammingHardTCS NQT · Infosys pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct Point { int x, y; };
struct Point p1 = {1, 2};
struct Point p2 = p1;
p2.x = 99;
printf("%d %d", p1.x, p2.x);
  1. A. 1 99
  2. B. 99 99
  3. C. 1 1
  4. D. 99 1

Correct answer: A. 1 99

`struct Point p2 = p1;` performs a whole-struct copy (memberwise), creating an independent object; mutating p2.x afterward does not affect p1.x, which remains 1, while p2.x becomes 99.

More C Programming questions

Exams that ask this topic