Murali
Murali

Reputation: 11

struct inside union and union having struct pointer. how to access them?

I'm working on structs and unions.

typedef struct _test {

        int te; 

}test;

typedef struct _resp {

        int type;
        union {
                test *testptr;    
        }u;

}resp_t;

resp_t *resp;

how to access te using resp?

Upvotes: 0

Views: 51

Answers (2)

cocool97
cocool97

Reputation: 1251

Don't forget to allocate enough space for your resp_t strcuture.
To access the element, just do resp->u.testprt->te

Upvotes: 0

KamilCuk
KamilCuk

Reputation: 142005

how to access te using resp?

resp->u.testptr->te;

Upvotes: 1

Related Questions