- 论坛徽章:
- 0
|
本帖最后由 csccyab 于 2019-02-15 11:40 编辑
- #include <stdio.h>
- struct A
- {
- int a1;
- int a2[100];
- };
- struct B
- {
- int B1;
- int countA;
- struct A *a;
- };
- struct C
- {
- int c1;
- struct A a;
- int countB;
- struct B *b;
- };
- void print_C_struct_member_values(struct C *c){
- printf("c_obj.a struct values are: %d, %d\n", c->a.a1, c->a.a2[0]);
- printf("c_obj.b struct values are: %d, %d\n", c->b->B1, c->b->countA);
- printf("c_obj struct values aree %d, %d\n", c->c1, c->countB);
- }
- int main() {
- struct B b_obj;
- struct C c_obj;
- c_obj.b = &b_obj;
- b_obj.a = &(c_obj.a);
- b_obj.a->a1 = 10;
- b_obj.a->a2[0] = 1;
- b_obj.B1 = 2;
- b_obj.countA = 3;
- c_obj.c1 = 4;
- c_obj.countB = 5;
- print_C_struct_member_values(&c_obj);
- }
复制代码 |
|