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);
}- A. 0
- B. Compilation error: struct parameters must be passed by pointer
- C. 1
- 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
- Assume a 64-bit LP64 ABI. What is printed? c struct Rect { struct { int x, y; } topLeft; struct { int x, y; } bottomRight; }; struct Rect…
- Assume a 64-bit LP64 ABI. What is printed? c typedef struct { int code; char message[20]; } Error; Error makeError(int c, const char msg)…
- Assume a 64-bit LP64 ABI. What is printed? c struct Counter { int value; }; void increment(struct Counter c) { c->value++; } int…
- Assume a 64-bit LP64 ABI. What is printed? c struct Pair { int a, b; }; struct Pair swapPair(struct Pair p) { int tmp = p.a; p.a = p.b…
- Assume a 64-bit LP64 ABI. What is printed? c struct Employee { char name[20]; int id; float salary; }; struct Employee e1 = {"Alice", 101…
- Assume a 64-bit LP64 ABI. What is printed? c struct Point { int x, y; }; struct Point make(int a, int b) { struct Point p = {a, b}; return…