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.
Tanveerkhan guttal said:
1 decade ago
Nicely explained by Teklit Ehiopia.
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.
Subhi said:
1 decade ago
Nicely explained by Teklit Ehiopia.
Mani said:
1 decade ago
Thanks for the clear explanation raghul
Pooja said:
1 decade ago
Thanks Rahul.
Naveen said:
1 decade ago
a[0][1][1] this means 1st block 2nd row 2nd coloumn right. ? its valus is 4. Am I right. ? please explain.
Subaa said:
1 decade ago
Nice explained chettan thank you.
Azagumozhi.M said:
9 years ago
@Teklit. Clear explanation.
HarshaN said:
1 decade ago
@shubham
No need of casting here as q in an integer point here.So q = (int*) arr; and q = arr; would result in same output.
No need of casting here as q in an integer point here.So q = (int*) arr; and q = arr; would result in same output.
J G Deepak said:
1 decade ago
1. a[1][1][1] is the last element. So a[1][1][1]=8.
2. The pointer *q always points to the first element of the array arr[][][], because of the initialization of q = (int*) arr. So *q represents the first element of the array.
Therefore the answer is 8,10.
2. The pointer *q always points to the first element of the array arr[][][], because of the initialization of q = (int*) arr. So *q represents the first element of the array.
Therefore the answer is 8,10.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers