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

22nd Jun 2020, 11:02 AM
Michael Nji
Michael Nji - avatar
5 Respuestas
+ 4
int a[10][10]; a[1][2]=5; printf("%d",a[1][2]);
22nd Jun 2020, 11:05 AM
Abhay
Abhay - avatar
0
Use int arr[n+1][m+1]; For declaring your array As it is 0 based indexing
22nd Jun 2020, 11:07 AM
Pulkit Kamboj
Pulkit Kamboj - avatar
0
@Abhay that works quite well for printing out, but for inserting values, it doesn't
22nd Jun 2020, 11:09 AM
Michael Nji
Michael Nji - avatar
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].
22nd Jun 2020, 11:16 AM
Pulkit Kamboj
Pulkit Kamboj - avatar
0
Oh ok I will try that. Thanks!
22nd Jun 2020, 11:27 AM
Michael Nji
Michael Nji - avatar