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);- A. 1 99
- B. 99 99
- C. 1 1
- 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
- Assume a 64-bit LP64 ABI. What is printed? c struct Node { int data; struct Node next; }; printf("%zu", sizeof(struct Node));
- Assume a 64-bit LP64 ABI. What is printed? c struct Mixed { short s; char c; int i; }; struct Reordered { int i; short s; char c; }…
- Assume a 64-bit LP64 ABI. What is printed? c struct S { int a; int b; }; struct S arr[3] = {{1,2},{3,4},{5,6}}; int p = (int )arr…
- Assume a 64-bit LP64 ABI. What is printed? c struct A { int x; }; struct B { struct A a; }; struct B b1 = {{10}}; struct B b2 = b1; b2.a.x…
- Assume a 64-bit LP64 ABI. What is printed? c struct S { double d; char c; }; struct S arr[2]; printf("%zu %ld", sizeof(arr), (char…
- Assume a 64-bit LP64 ABI. What is printed? c union Shape { struct { double radius; } circle; struct { double width, height; } rect; }…