ProgrammingHardIBM · Deloitte pattern
Assume a 64-bit LP64 ABI. What is printed?
Assume a 64-bit LP64 ABI. What is printed?
struct A { int x; };
struct B { struct A a; };
struct B b1 = {{10}};
struct B b2 = b1;
b2.a.x = 20;
printf("%d %d", b1.a.x, b2.a.x);- A. 10 20
- B. 20 20
- C. 10 10
- D. 20 10
Correct answer: A. 10 20
Whole-struct assignment (b2 = b1) recursively copies nested struct members by value too, so b2.a is an independent copy of b1.a; mutating b2.a.x doesn't touch b1.a.x, which stays 10.
More C Programming questions
- 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; }…
- Assume 32-bit int and two's complement. What is printed? c int x = 5; int y = ~x + 1; printf("%d", y);
- Assume 32-bit int. What is printed? c int x = 12; printf("%d %d %d", x & 1, x | 1, x ^ 1);
- Assume 32-bit int. What is printed? c int a = 6, b = 3; printf("%d %d %d %d", a & b, a | b, a ^ b, ~a);
- Assume 32-bit int. What is the value of n that checks whether the k-th bit (0-indexed from the LSB) of x is set, for x=44 and k=3, and…