简体   繁体   English

编译警告。数组初始化程序中的多余元素

[英]Compilation Warning.Excess elements in array initializer

I was implementing a multi dimensional array and using pointers and testing the correctness of the address allotment.Even though the program ran perfectly and all the addresses were same as i expected.But there was a compilation warning [Warning] excess elements in array initializer .Can anyone explain about the warning.The code is below.... 我正在实现一个多维数组,并使用指针并测试了地址分配的正确性。即使程序运行完美并且所有地址都与我期望的相同。但是[Warning] excess elements in array initializer有一个编译警告[Warning] excess elements in array initializer 。任何人都可以解释该警告。代码如下。

#include<stdio.h>
    int main(){
    int c[3][2][2] = {{{2,5},{7,9},{3,4},{6,1},{0,8},{11,13}}};
    printf("%d %d %d %d",c,*c,c[0],&c[0][0]);
    return 0;
}

The error summary is like this 错误摘要是这样的

        In function 'main':
3   2   [Warning] excess elements in array initializer
3   2   [Warning] (near initialization for 'c[0]')
3   2   [Warning] excess elements in array initializer
3   2   [Warning] (near initialization for 'c[0]')
3   2   [Warning] excess elements in array initializer
3   2   [Warning] (near initialization for 'c[0]')
3   2   [Warning] excess elements in array initializer
3   2   [Warning] (near initialization for 'c[0]')

You have three pairs of a pair of int s. 您有三对一对int The initialization should be: 初始化应为:

int c[3][2][2] = {{{2,5},{7,9}},{{3,4},{6,1}},{{0,8},{11,13}}};
      3                 ^             ^             ^
         2           ^     ^
            2       ^ ^          

That is not a three dimensional array. 那不是三维阵列。 You forgot a brace! 你忘了撑!

int c[3][2][2] = {{{2,5},{7,9}},{{3,4},{6,1}},{{0,8},{11,13}}};

Perhaps reformat things to make it clearer: 可能重新格式化以使其更清楚:

int c[3][2][2] = {
    { {2,5}, {7,9} }, 
    { {3,4}, {6,1} },
    { {0,8}, {11,13} }
};

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

相关问题 警告:数组初始值设定项中的多余元素 - warning: excess elements in array initializer 数组初始化程序中的多余元素 - Excess elements in array initializer 打印二维数组:警告:数组初始值设定项中的元素过多 - printing a 2D array :warning: excess elements in array initializer char数组初始化程序中的多余元素 - excess elements in char array initializer 通过指向 2D 字符数组的指针访问。 警告:数组初始值设定项中的多余元素 - access via pointer to 2D char array. warning: excess elements in array initializer C:警告:数组初始值设定项中的元素过多; &#39;xxx&#39; 即将初始化; 需要“char *”,但类型为“int” - C: warning: excess elements in array initializer; near initialization for ‘xxx' ; expects ‘char *’, but has type ‘int’ C 警告:数组初始化程序中的多余元素和程序未提供预期的 output - C warning: excess elements in array initializer and program does not provide expected output char数组初始值设定项错误中的多余元素 - Excess elements in char array initializer error 在数组初始值设定项中有多余的元素可以吗? - Is it ok to have excess elements in array initializer? 错误:char数组初始化程序中的多余元素 - error: excess elements in char array initializer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM