C Programming - Structures, Unions, Enums - Discussion

Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 9)
9.
Point out the error in the program?
#include<stdio.h>

int main()
{
    struct emp
    {
        char n[20];
        int age;
    };
    struct emp e1 = {"Dravid", 23};
    struct emp e2 = e1;
    if(e1 == e2)
        printf("The structure are equal");
    return 0;
}
Prints: The structure are equal
Error: Structure cannot be compared using '=='
No output
None of above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
17 comments Page 2 of 2.

Atul said:   1 decade ago
Can anyone explain why we can't compare structure?

Vanitadevi said:   1 decade ago
I need more explanation for this can any one explain?

Jains said:   1 decade ago
Ya it is not!

Arun said:   1 decade ago
It is not possible in case of structures?

Vinay said:   1 decade ago
Structure cannot be compared here because you are assigning the same value of e1 to the e2 which is not allowed, since it is possible in some cases but only if you have * variables.

Zombie said:   1 decade ago
Why can't structures be compared? They are "value type variables" ?

Srividhya said:   2 decades ago
Entire structure cannot be compared. It can be done only on a member wise comparison.


Post your comments here:

Your comments will be displayed after verification.