本文介绍了howto init 2d结构为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好, 我有一个问题: 是否可以将二维结构数组初始化为零? 例如我使用数组。 int array [MAX] = {0} 但是: 结构测试bb [MAX] [MAX] = {{0},{0}}; 不工作..? 谢谢你。 Stef。Hello,I have a question:Is it possible to init a 2d array of structures to zero ?For example with array I do.int array[MAX] = {0}but:structure test bb[MAX][MAX] = {{0},{0}};won''t work.. ?thank yoo.Stef.推荐答案 但编译器发出警告然后......如: istrct.c:在函数`main'': istrct.c:11:警告:初始化器周围缺少大括号 istrct.c: 11:警告:(接近初始化'aaaa [0]'') istrct.c:12:警告:初始化程序周围缺少大括号 istrct.c:12:警告:(接近初始化`bbbb [0]'') istrct.c:12:警告:未使用的变量`bbbb'' istrct.c:11:警告:未使用的变量`aaaa'' 完整性这是一个小的简单骨架.. #include< stdio.h> #define MAXTAB 100 #define MAXCOL 3 struct tab { double freq; }; int main(void){ struct tab aaaa [MAXTAB] [MAXCOL] = {0}; struct tab bbbb [MAXTAB] [MAXCOL] = {0}; 返回0; }But the compiler gives warnings then... like:istrct.c: In function `main'':istrct.c:11: warning: missing braces around initializeristrct.c:11: warning: (near initialization for `aaaa[0]'')istrct.c:12: warning: missing braces around initializeristrct.c:12: warning: (near initialization for `bbbb[0]'')istrct.c:12: warning: unused variable `bbbb''istrct.c:11: warning: unused variable `aaaa''For completeness Here is small simple skeleton..#include <stdio.h>#define MAXTAB 100#define MAXCOL 3struct tab {double freq;};int main(void) {struct tab aaaa[MAXTAB][MAXCOL] = {0};struct tab bbbb[MAXTAB][MAXCOL] = {0};return 0;} 但是编译器发出警告然后......就像: br /> istrct.c:在函数main中: istrct.c:11:警告:初始化程序周围缺少大括号 istrct.c:11:警告:(接近初始化为`aaaa [0 ]'') istrct.c:12:警告:初始化程序周围缺少大括号 istrct.c:12:警告:(接近初始化为`bbbb [0]'') istrct。 c:12:警告:未使用的变量`bbbb'' istrct.c:11:警告:未使用的变量`aaaa''完整性这是一个小的简单骨架.. #include< ; stdio.h中> #define MAXTAB 100 #define MAXCOL 3 struct tab { double freq; }; int main(void){ struct tab aaaa [MAXTAB] [MAXCOL] = {0}; struct tab bbbb [MAXTAB] [MAXCOL] = {0}; But the compiler gives warnings then... like: istrct.c: In function `main'': istrct.c:11: warning: missing braces around initializer istrct.c:11: warning: (near initialization for `aaaa[0]'') istrct.c:12: warning: missing braces around initializer istrct.c:12: warning: (near initialization for `bbbb[0]'') istrct.c:12: warning: unused variable `bbbb'' istrct.c:11: warning: unused variable `aaaa'' For completeness Here is small simple skeleton.. #include <stdio.h> #define MAXTAB 100 #define MAXCOL 3 struct tab { double freq; }; int main(void) { struct tab aaaa[MAXTAB][MAXCOL] = {0}; struct tab bbbb[MAXTAB][MAXCOL] = {0}; 使用 struct tab aaaa [MAXTAB] [MAXCOL] = {{{0}}}; 如果你有例如你会做的二维数组例如 int foo [2] [2] = {{1,2},{3,4}}; 由于结构的初始化程序需要花括号,你需要 为你的二维结构数组提供另一个级别。 如果结构中有多个成员为每个成员加上一个值为,即 struct tab2 { double freq; int x; } struct tab2 ccc [MAXTAB] [MAXCOL] = {{{ 0,0}}}; 问候,Jens - \ Jens Thoms Toerring ___ 济*********** @ physik.fu-berlin.de \ __________________________ http://www.toerring.de 这篇关于howto init 2d结构为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS!
05-24 06:25