int a[MAX_ROWS][MAX_COLS];We can initialize the contents of a 2D array, several ways:
int i,j,k = 0; for(i = 0; i < MAX_ROWS; i++) for(j = 0; j < MAX_COLS; j++) a[i][j] = k++;
int i,j; FILE *fp; if((fp = fopen("file","r")) == NULL) { fprintf(stderr,"Unable to open file\n"); exit(1); } for(i = 0; i < MAX_ROWS; i++) for(j = 0; j < MAX_COLS; j++) fscanf(fp, "%d", &a[i][j]); fclose(fp);
int a[MAX_ROWS][MAX_COLS] = { {1,2,3}, {4,5,6}, {7,8,9} };