I'm currently learning C language from youtube and this is one of the code about the 2D arrays:
#include<stdio.h>
int main()
{
int const columns = 3;
int const rows = 2;
int grades[rows][columns] = {
{12, 23, 45},
{64, 78, 89}
};
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
printf("%d ", grades[i][j]);
}
}
return 0;
}
But when I try to run it, it shows the error "error: variable-sized object may not be initialized"
int grades[rows][columns] = {
| ^~~
tempCodeRunnerFile.c:8:10: warning: excess elements in array initializer
8 | {12, 23, 45},
| ^~
tempCodeRunnerFile.c:8:10: note: (near initialization for 'grades[0]')
So on and so forth. I can't figure it out and it keeps struggling me.