0

hi,
If I have a union like

union Type
{
    struct Student s;
    struct Employee e;
}type;
and a struct person like


struct Person
{
    char firstname[10];
    char familyname[20];
    char telephone[10];
    union Type type;
}p;

how can i check whether type of union in person is student or employee?can i say this: if(p.type==s)
thanks

2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by sepp2k
0

You can't, you need a separate field (usually of an enum type) to keep track of which field of the union is set.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.