ProgrammingHardWipro · Cognizant pattern

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

Assume a 64-bit LP64 ABI. What is printed?
struct Point { int x, y; };
void tryModify(struct Point p) { p.x = 999; }
int main(void) {
    struct Point pt = {1, 2};
    tryModify(pt);
    printf("%d", pt.x);
}
  1. A. 0
  2. B. Compilation error: struct parameters must be passed by pointer
  3. C. 1
  4. D. 999

Correct answer: C. 1

tryModify receives struct Point BY VALUE, a complete independent copy; mutating the parameter p inside the function has no effect whatsoever on the caller's pt, which remains unchanged at 1.

More C Programming questions

Exams that ask this topic