Answer to Question #44260 in C for Vijayasurya

Question #44260
//Accessing 2 dimensional array element through pointer.
This is the program.
Void main()
{
int a[3][3],i,j;
int *p;
clrscr();
printf("\n Enter the matrix elements\n);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
p=&a[0][0];
printf("\n Matrix elements:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%4d",*(p+3*i+j);
printf("\n");
}
}
In this program I'm not able to understand and trace the printing of array elements using the pointer.
Please Help. Why is the pointer incremented to 3 ... In fact I dont understand *(p+3*i+j) :( .... please help me in tracing the output.
0
Expert's answer

Answer in progress...

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS