This is your original code (as a reference):
Code:
#include <stdio.h>
void fun(int (*n)[][]);
main() {
int n[2][3] = {{ 11, 12, 13 },{ 21, 22, 23 }};
fun(&n);
}
void fun(int (*n)[][]) {
printf("%d\n", (*n)[1][1]);
}
Code:
int n[2][3] = {{ 11, 12, 13 },{ 21, 22, 23 }};
I really wished this worked, but I'm afraid we have to stream it like this:
Code:
int n[2][3] = {11, 12, 13, 21, 22, 23 };
You had the function like this:
Code:
void fun(int (*n)[][])
But that would be a uuhh..triarray multitwilight zone something... remember we're making this a grid type array (2 dimensional), not 3 dimensional. So it would come down to something like this:
Code:
void fun(int[][3]);
And we're also going to have to remember the 3 as a column.
And then you had:
Code:
printf("%d\n", (*n)[1][1]);
Remember that's the same thing as saying:
Code:
printf("%d\n", n[0][1][1]);
And that's wrong, because we aren't dealing with an array that's 3 dimensional, we're dealing with a two dimensional array, so the correct approach would be like this:
Code:
printf("%d\n", n[1][1]);
And that would give us 22.
Here's the final code:
Code:
#include <stdio.h>
void fun(int[][3]);
int main() {
int n[2][3] = { 11, 12, 13, 21, 22, 23 };
fun(n);
}
void fun(int n[][3]) {
printf("%d\n", n[1][1]);
}