联合内部的结构和具有结构指针的联合。如何访问它们?

问题描述 投票:0回答:2

我正在研究结构和联合。

typedef struct _test {

        int te; 

}test;

typedef struct _resp {

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

}resp_t;

resp_t *resp;

如何使用resp访问te?

c structure unions
2个回答
0
投票

如何使用resp访问te?

resp->u.testptr->te;

0
投票

不要忘记为resp_t结构分配足够的空间。要访问元素,只需执行resp->u.testprt->te

© www.soinside.com 2019 - 2024. All rights reserved.