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 2 of 6.
Ibrahem said:
1 decade ago
Try this in this code :
printf("%d\n",*arr);
........
The output is garbage ! why ?
p= arr;
So *p = *arr ?
printf("%d\n",*arr);
........
The output is garbage ! why ?
p= arr;
So *p = *arr ?
Nikhil Gavali said:
8 years ago
It will not read the matrix only if it [2][1][1] because it is 3*3 matrix and in above program we consider matrix as 2*2.
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.
Priyanka said:
10 years ago
@Megha.
There is only two block present i.e. 0 & 1. So value not present at this location.
There is only two block present i.e. 0 & 1. So value not present at this location.
ArunKumar A said:
10 months ago
@All.
arr[0][0][0]={10, 2};
arr[0][0][1]={3, 4};
arr[0][1][1]={5, 6};
arr[1][1][1]={8, 0};
arr[0][0][0]={10, 2};
arr[0][0][1]={3, 4};
arr[0][1][1]={5, 6};
arr[1][1][1]={8, 0};
(1)
Kiran sp said:
1 decade ago
Hi friends, can any one tell me, how the elements in 3d array are allocated. ?
Shubham said:
1 decade ago
Please answer me. What significance for sentence below it.
q = (int*) arr;.
q = (int*) arr;.
Megha said:
10 years ago
What the value if it is a[ 2 ] [ 1 ] [ 1 ]? Please someone explain.
Prathyusha said:
8 years ago
Can anyone explain how 4D array can be represented with an example?
Punit said:
1 decade ago
Why the statement q = (int*) arr? Why this type casting is done?
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers