int f(int b[][3]);
int main()
{
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
f(a);
printf("%d\n", a[2][1]);
}
int f(int b[][3])
{
++b;
b[1][1] = 1;
}
3x3 => 9 elements contained in the 2-D array a. When it’s passed, then b will contain the the base address of the a. If suppose base address is 1000 then ++b how does it to 3 locations and not 9 locations ahead? Are we doing typecasting when the variable a is passed to b[][3] as only the three elements?
How does b[1][1] correspond to the address of 8 and not 5?
We can’t do incrementing or decrementing in an array as array is a const pointer, but how is that they are incrementing ++b as its an array?
The function heading
is a nothing more than a confusing way to write (and is exactly equivalent to)
The type of
bis “pointer to three-element array ofint“. When you increment thebparameter you adjust it to point to the next three-element array ofint— now it points to{4,5,6}. Thenb[1]indexes once more and gives you the array{7,8,9}and finallyb[1][1]gives you the oneth element of that array, namely8.