C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 11)
11.
What will be the output of the program?
#include<stdio.h>
int main()
{
int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};
int *p, *q;
p = &arr[1][1][1];
q = (int*) arr;
printf("%d, %d\n", *p, *q);
return 0;
}
Discussion:
58 comments Page 5 of 6.
Satishp said:
1 decade ago
a[0][0][0]=10;
a[0][1][1] =2;
0 1 ->blocks
0 1 0 1 ->sub blocks
10 2 3 4 5 6 7 8 ->values
0 1 0 1 0 1 0 1 ->sub blocks of sub blocks
3-D REPRESENTATION OF ARRY IS
blocks-subblocks-subblocks of subblocks-values
then a [0] [1] [1] = 4
a [1] [1] [0] = 7 .so i think it is correct.
a[0][1][1] =2;
0 1 ->blocks
0 1 0 1 ->sub blocks
10 2 3 4 5 6 7 8 ->values
0 1 0 1 0 1 0 1 ->sub blocks of sub blocks
3-D REPRESENTATION OF ARRY IS
blocks-subblocks-subblocks of subblocks-values
then a [0] [1] [1] = 4
a [1] [1] [0] = 7 .so i think it is correct.
Tanveerkhan guttal said:
1 decade ago
Nicely explained by Teklit Ehiopia.
Kiran sp said:
1 decade ago
Hi friends, can any one tell me, how the elements in 3d array are allocated. ?
Swanand said:
1 decade ago
Good rahul hope you explain in future like this.
VENU said:
1 decade ago
@SAGAR
Its 7.
Its 7.
Sagar Kapadiya (Surat) said:
1 decade ago
Value if its a[ 2 ] [ 2 ] [ 1 ].. ?
Teklit Ehiopia said:
1 decade ago
This is 3D array you can look at this diagram so that easly understand it
arr[1][1][1]==>block 2,row 2,colum 2; ==>[8].
arr mean arr[0][0][0]==>block 1 row 1 column; ==>[10]
1stblock R1| 10 . 2| 2nd block R1| 5 . 6 |
|_______| |_______|
R2 | 3 , 4| R2| 7 . 8 |
|_______| |_______|
C1 C2 C1 C2
arr[1][1][1]==>block 2,row 2,colum 2; ==>[8].
arr mean arr[0][0][0]==>block 1 row 1 column; ==>[10]
(1)
Yeswanth said:
1 decade ago
Well said rahul.
Mani said:
1 decade ago
Thanks for the clear explanation raghul
Arvind said:
1 decade ago
Nice explaind rahul.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers