出于某种原因,我有这样的想法,C和C的工作方式如下:
int foo[10] = {57}; for (int i=0; i<10; ++i) assert (foo[i] == 57);
原来剩下的整数被初始化为0而不是57.我从哪里得到这个想法?这一点是真的吗?结构初始化列表是否真的如此?当分配给= {}和= {0}时,数组和结构是否整齐且正确地开始将自己初始化为0值?除非明确说明,否则我一直认为他们会初始化为垃圾.
解决方法
只要初始化器存在,就一直都是这样. C89说:
If there are fewer initializers in a list than there are members of an aggregate,the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.