LearnFrenzy
Sign in Take a free test

Structures, Unions, Enums · Structures, Unions & Enums MCQ · Question 3

Can two structures be compared with == in C? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

Given two variables a and b of the same struct type, which is true?

  • A a == b does not compile; compare the members (or write a function) Correct
  • B a == b compares all members
  • C a == b compares their addresses
  • D a == b compares only the first member
Correct Answer: Option A

C defines assignment for structs but not equality. memcmp(&a, &b, sizeof a) is also unsafe, because padding bytes may contain different garbage. Compare member by member.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links