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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.