0
Inserting data into a 2 dimensional array in C
Lets say we have a 2d array Arr with dimensions N*M, how do we insert values into lets say position Arr [n][m] ?? I tried doing that by indexing it directly (I.e Arr [n][m] ) but I got an error pointing at index m saying that 《the suscripted value is neither an array nor pointer nor vector. 》 Please help a fellow coder
5 Antworten
+ 4
int a[10][10];
a[1][2]=5;
printf("%d",a[1][2]);
0
Use
int arr[n+1][m+1];
For declaring your array
As it is 0 based indexing
0
@Abhay that works quite well for printing out, but for inserting values, it doesn't
0
Bunny 🐰🐰 it works fine in inserting values, that's why we are able to print it but the point is if you declare with
arr[n][m], then for arr[i][j] the of I can vary from 0 to n-1 and j can vary from 0 to m-1 i.e. you cannot insert at arr[n][m].
0
Oh ok I will try that. Thanks!