1,568 views
1 votes
1 votes
#include<stdio.h>

int main() {
int array[2][3]={5,10,15,20,25,30};
int (*ptr)[2][3]=&array;
printf("%d\t",**(*ptr+1));
}
can someone explain how is it "20"??

3 Answers

1 votes
1 votes

let array 

a[2][3]={5,10,15,20,25,30};  here a will hold the address of initial elements of array....

here *a=a  and **a=*(*(a+1)+0)=a[1][0] will print 20....means 1th row and 0th column....

now in this case...

 (*ptr)[2][3]=&a ....then  *ptr=a and then like above.....
 

,**(*ptr+1) also can be written as *(*(*ptr+1)+0) or *(*(a+1)+0) or a[1][0].....

0 votes
0 votes
In computer a 2D array is stored in row major order and ptr is a pointer which points to the row of array means ptr+0 points to first row...ptr+1 points to second row so *ptr+1 points to the address of  second row....and**(*ptr+1) will give the value stored at*ptr+1 i.e.,20
edited by

Related questions

2 votes
2 votes
1 answer
1
1 votes
1 votes
1 answer
2
Na462 asked Jan 8, 2019
1,436 views
#include <stdio.h>main (){unsigned x = -10;int X = 20;if (X x) printf ("Hello");else{ printf ("%d",x); printf ("Jello"); }}
7 votes
7 votes
3 answers
3
Parshu gate asked Nov 20, 2017
780 views
What is the output of the following program?#include<stdio.h int main() { int array[]={10, 20, 30, 40}; printf(“%d”, -2[array]); return 0; }$-60$$-30$$60$Garbage valu...
3 votes
3 votes
1 answer
4
Parshu gate asked Nov 13, 2017
1,409 views
main( ){int n[3][3] = {2, 4, 3,6, 8, 5,3, 5, 1} ;printf ( "\n%d %d %d", *n, n[3][3], n ) ;}