1 votes 1 votes Int a[2][2][2]={{10,2,3,4},{5,6,7,8}}; int *p; p=&a[2][2][2]; printf("%d",*p); this gives garbage value,what should be the changes to get p value as 10 A_i_$_h asked Jun 15, 2017 A_i_$_h 759 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes a[0] a[1] a[0][0] a[0][1] a[1][0] a[1][1] a[0][0][0] a[0][0][1] a[0][1][0] a[0][1][1] a[1][0][0] a[1][0][1] a[1][1][0] a[1][1][1] 10 2 3 4 5 6 7 8 In 3D Arrays a[i][j][k] = *(a[i][j] + k) = *(*(a[i] + j ) + k) = *(*(*(a + i) + j ) + k) and pointer to 3D array is METHOD 1 : int (*p)[2][2] = a; To get value of 10 ie a[0][0][0] i=0 , j=0 , k=0 *(*(*( a + 0) + 0) + 0) = ***a OR *(*(*( p + 0) + 0) + 0) = ***p METHOD 2 : int *p = (int*)(&a); for (i=0;i<8;i++) { printf("%d\n",*(p + i)); } Aashish S answered Jun 15, 2017 edited Jun 15, 2017 by Aashish S Aashish S comment Share Follow See all 13 Comments See all 13 13 Comments reply Show 10 previous comments Aashish S commented Jun 16, 2017 reply Follow Share i think you know better now so try urself... as programming is never done by asking doubts its rather done by practising and asking your doubts to computer..dont waste time ur precious time in questioning 0 votes 0 votes A_i_$_h commented Jun 16, 2017 reply Follow Share okay :) 0 votes 0 votes Aashish S commented Jun 16, 2017 reply Follow Share for ur doubt int*p=&a; is correct or not - read the previous comments carefully the answer there... 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes p=&a[0][0][0]; now printf("%d", *p); will give u the 10 Saurabh_Verma answered Sep 4, 2017 Saurabh_Verma comment Share Follow See all 0 reply Please log in or register to add a comment.