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 6 of 6.
Harishgoud said:
1 decade ago
Exactly the answer is right Mr. Rahul.
Abhijit said:
1 decade ago
@haneef:
a[2][1][1] cannot be accessed, coz array is initialized only for the 2nd dimension(i.e 0,1) a[2]... will be like accessing the thrid element which is not initialized.
Hope you got it.
a[2][1][1] cannot be accessed, coz array is initialized only for the 2nd dimension(i.e 0,1) a[2]... will be like accessing the thrid element which is not initialized.
Hope you got it.
(1)
Sanjay said:
1 decade ago
Thank you sagar.
Cool said:
1 decade ago
Good one dude! (rahul).
(1)
Haneef said:
1 decade ago
Rahul. What the value if its a[ 2 ] [ 1 ] [ 1 ]. ?
Sagar said:
1 decade ago
It is three dimensional array,
so,arr[1][1][1]=8,
*p,
p=&arr[1][1][1],
*p means value at address i.e=8.
(int*)arr always consist first value as,
starting value at arr address,so
o/p= 8,10
so,arr[1][1][1]=8,
*p,
p=&arr[1][1][1],
*p means value at address i.e=8.
(int*)arr always consist first value as,
starting value at arr address,so
o/p= 8,10
(1)
Nancy said:
1 decade ago
Good explanation rahul.
RAHUL SHARMA said:
1 decade ago
Here the 3-D array the value can be store as:
and the *arr represent the first number of a array is 10.
Then hence the number is (8,10).
a[2][2][2]={
{
10,2
3,4 // First Block
}
{
5,6
7,8 //Second Block
}
}
a[ 0 ] [ 0 ] [ 0 ] =10;
| | |
Block Rows Columns
a [ 1 ] [ 1 ] [ 1 ] = 8;
| | |
2'Block 2'Row 2'column
and the *arr represent the first number of a array is 10.
Then hence the number is (8,10).
(38)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers