简体   繁体   English

数组声明和结构初始化

[英]Array declaration and initialization with structs

I am trying to declare an array of structs , is it possible to initialize all array entries to a default struct value? 我正在尝试声明一个structs数组,是否可以将所有数组条目初始化为默认struct值?

For example if my struct is something like 例如,如果我的struct类似于

           typedef struct node
           {    int data;
                struct node* next;
           }node;

Is there a way to declare data to 4 and next to null ? 有没有办法将数据声明为4并在null旁边? What about 0 and null ? 那么0null呢?

Sure: 当然:

node x[4] = { {0, NULL}, {1, NULL}, {2, NULL}, {3, NULL} };

Even this should be fine: 即使这样也可以:

node y[4] = { {0, y + 1}, {1, y + 2}, {2, y + 3}, {3, NULL} };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM