I can use pointer for one-dimension array for function, but I don’t know use the same technique for two-dimension array.
Here is my example code :
int main(){
int b[10]; //initialize b
Print(b);
int a[10][10]; //initialize a
Print2(a);
}
void Print(int*b){
for(int i=0; i<10; i++)
printf("%d\n",*(b+i));
}
// I want to use same technique here
// but i have met error
void Print2(int*a){
for(int i=0; i<10; i++)
for(int j=0; j<10; j++)
printf("%d\n",*(*(a+i)+j)); // error at this line
}
Please help me how to use same technique of one-dimension array for two-dimension array.
Thanks 🙂
destroy the inner * and multiply i with 10 then add j
because going “downwards” in a 2d matrix, you go through dimension-1(10 in this example) elements.
for 3d:
for N-dimensions: