2D array indexing

hi

this works
1
2
3
4
5
int main()
{
	int arr[5];
	*(arr+1) = 10;
}


this gives error, since its a 2D array .but arr gives the base address when printed out .If i use *(&arr[0][0]+1) instead of *(arr+1) i dont get errors,where am i wrong
1
2
3
4
5
int main()
{
	int arr[2][3];
	*(arr+1) = 5;
}
You get the error on the second tests because it is a 2 dimension array (let's not argue here about whether arrays have diemnsions).
therefore EACHelement of the first ddimension contains an array of 3 integers.

So in the second example the result of *(arr+1) is int array[3] so *(arr+1) = 5; is saying
int [3] =5 which is incorrect.

so arr[1][0]=5 using pointers would be **(arr+1) = 5;
Last edited on
thank u
Topic archived. No new replies allowed.