[英]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
? 那么
0
和null
呢?
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.