简体   繁体   中英

warning: excess elements in array initializer

I'm trying to create 2D array.

int main() {
    int stalagmite[10][6] = { { 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 },
                              { 1, 0, 0, 1, 1, 0, 1, 0, 0, 1 },
                              { 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
                              { 1, 1, 0, 1, 1, 1, 0, 1, 0, 0 },
                              { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 },
                              { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 } };

    printf("%d\n", stalagmite[3][3]);
}

Output as follows:

deneme.c:9:51: note: (near initialization for ‘stalagmite[5]’)
deneme.c:9:54: warning: excess elements in array initializer
9 |                         { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0 } };

Trying to define an array with initializer. When I try to compile it always return a error stated above. I tried to change size, data type but it had no effects.

int stalagmite[10][6] defines an array of 10 arrays of 6 int , whereas your initializer specifies 6 arrays of 10 integers.

The definition should probably be changed to int stalagmite[6][10] = {...} or possibly int stalagmite[][10] = {...} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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