Q: How would you check whether the contents of two structure variables are same or not?
- Show Answer
- Workspace
- Discuss
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.
Similar Questions
Since Nithya and Suganya exchange places, so Rita’s new position is the same as Monika’s earlier position. This position is 17th from the right and 10th from the left. Therefore Number of girls in the row = (16 + 1 + 9) = 26.