Question 2
Back to Exercise
The program below has a problem. Which statement correctly describes it?
#include <stdio.h>
struct point {
int x, y;
};
int main(void) {
struct point a = {1, 2}, b = {1, 2};
if (a == b)
puts("same");
return 0;
}
- A a and b must be pointers
- B C has no == for structures; compare a.x == b.x && a.y == b.y Correct
- C There is no error; it prints same
- D The initializers are invalid
Correct Answer: Option B
The compiler rejects == on struct operands. Compare the members, ideally inside a small function such as bool point_eq(struct point a, struct point b).
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!