#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int ar[2][2] = {1,2,3,4};
int **p= NULL , i=0, j=0;
p = ar; //compiler error. Confused ! Do i need to assign &a or anything.
puts("OUT: ");
for(i = 0; i < 2; i++)
{
for(j = 0 ; j < 2; j++)
{
printf("%2d", *(*(ar + i) + j));
printf("%2d", *(*(p + i) + j)); /* This is wrong . Compiler error */
}
}
exit(0);
}
I want to create a pointer to the 2D array so that instead of ar in the for loop
i should be able to put p. I'm confused. I know other methods of accessing 2d
elements but i'm confused with this example.