Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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] = {...}.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading