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.

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

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

Sanju said:   1 decade ago
It possible to compare only when there must be pointer variable else error.

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

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

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

Jains said:   1 decade ago
Ya it is not!


Post your comments here:

Your comments will be displayed after verification.