Function returning pointer to union in c programming


Return type of function pointer to union in c programming language

typedef union novel{
    int count;
    double volume;
}*P,*Q,T;
P iim(){
    static T t={625};
    Q q=&t;
    return q;
}
void main(){
    T *r;
    r=iim();
    clrscr();
    printf("%-d",r->count);
    getch();
}

Output:625




typedef union employee{
char *name;
int id;
}EMP;
EMP display();
void main(){
EMP list;
list=display();
clrscr();
printf("%s ",list.name);
getch();
}
EMP display(){
EMP list1={"MOTI"};
EMP list2={"TOM"};
return list1,list2;
}


Output: TOM

No comments: