Join ExamsbookAnswer :
How would you check whether the contents of two structure variables are same or not?5
Q: How would you check whether the contents of two structure variables are same or not?
- Show AnswerHide Answer
- Workspace
Answer :
Explanation :
struct emp { char n[20]; int age; }; main() { struct emp e1 = {"Dravid", 23}; struct emp e2; scanf ("%s %d",e2.n, & e2.age); if( structcmp (e1,e2) ==0) printf ("The structures are equal"); else printf ("The structures are unequal"); } structcmp ( struct emp x, struct emp y) { if (strcmp (x.n,y.n) ==0) if (x.age == y.age) return (0); return (1); } In short, if you nee to compare two structures, you'll have to write your own function to do so which carries out the comparison field by field.