Question 11
Back to Exercise
What is the output of the following C program on a 64-bit system?
#include <stdio.h>
int main(void) {
struct { int a, b; } s1 = {1, 2}, s2;
s2 = s1;
s2.b = 9;
printf("%d %d\n", s1.b, s2.b);
return 0;
}
- A 2 9 Correct
- B 9 9
- C 2 2
- D Compilation error
Correct Answer: Option A
Both variables are declared in one declaration, so they share the same (unnamed) type and can be assigned. The assignment copies, so changing s2 leaves s1 alone.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!