Difficulty: Easy
Correct Answer: Error: Structure cannot be compared using '=='
Explanation:
Introduction / Context:
The question targets whether C permits comparing entire structures using the == operator. Copying one struct to another is allowed, but comparison is a different rule.
Given Data / Assumptions:
Concept / Approach:
Standard C allows assignment between compatible structure types (e2 = e1) but does not define == or != for entire structure operands. You must compare field-by-field, e.g., using strcmp for character arrays and direct comparison for integers.
Step-by-Step Solution:
Verification / Alternative check:
Compilers emit an error like “invalid operands to binary == (have struct emp and struct emp)”. Fieldwise comparison compiles and behaves as expected.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming struct comparison works like in C++ or in some compiler extensions. In portable C, compare members explicitly.
Final Answer:
Error: Structure cannot be compared using '=='
Discussion & Comments