How to use a struct inside another struct?

前端 未结 7 1334
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-05 21:05

I want to use a nested structure but i dont know how to enter data in it, for example:

struct A {
    int data;
    struct B;
};
struct B {
    int number;
};
         


        
7条回答
  •  温柔的废话
    2021-02-05 21:27

    struct A {
        struct B {
           int number;
        };
        B b;
        int data;
    };
    int main() {
        A a;
        a.b.number;
        a.data;
    }
    

提交回复
热议问题