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 origin = {0, 0};
struct Point *p1 = &origin;
struct Point *p2 = &origin;
p1->x = 5;
printf("%d %d", p2->x, origin.x);- A. 0 0
- B. 5 0
- C. 0 5
- D. 5 5
Correct answer: D. 5 5
p1 and p2 both point at the SAME struct, origin; there is no copying involved here, just two pointers to one object. Modifying *p1's x field directly modifies origin's own x, and p2 (pointing at that same memory) sees the update too: both read 5.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Config { int verbose : 1; int debug : 1; int level : 4; }; struct Config cfg = {0}…
- What is printed? c int sumDigits(int n) { if (n == 0) return 0; return (n % 10) + sumDigits(n / 10); } int main(void) { printf("%d"…
- What is printed? c int countDown(int n) { if (n < 0) return 0; printf("%d ", n); return countDown(n - 1); } int main(void) { countDown(3); }
- What is printed? (Assume a 64-bit LP64 ABI, where long is 8 bytes.) c long fact(int n) { return n <= 1 ? 1 : n fact(n - 1); } int…
- What is printed? (Assume int is 32 bits.) c int a = -1; unsigned int b = (unsigned int)a; printf("%u", b);
- What is printed? (Check if two integers have opposite signs, without using multiplication.) c int oppositeSigns(int a, int b) { return (a…