C Programming - Pointers - Discussion

Discussion Forum : Pointers - Find Output of Program (Q.No. 18)
18.
What will be the output of the program assuming that the array begins at location 1002?
#include<stdio.h>

int main()
{
    int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2}, 
                       {2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
    printf("%u, %u, %u, %d\n", a, *a, **a, ***a);
    return 0;
}
1002, 2004, 4008, 2
2004, 4008, 8016, 1
1002, 1002, 1002, 1
Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
54 comments Page 4 of 6.

Sriram said:   1 decade ago
'a' holds the starting address of 3d array here. So it will be 1002,
In a[][][], the first bracket represents the z-direction view. Second bracket represents rows(X-direction). 3rd brackets represents columns (Y-direction).

*a is nothing but a[][] is the starting address of 2d array in xy-direction.

**a is nothing but a[] is the starting address of 1d array in y-direction.

***a is value at stating of 3d array a

So answers will be: *a=1002, **a=1002, ***a=1.

GURU said:   1 decade ago
I need some more explanation.

RAHUL said:   1 decade ago
3D array means?

Cfriend said:   1 decade ago
Three dimensional array
ex a[1][2][3]
it contain 6 elements
it's meaning is 1, 2 dimensional array of size [2][3]
and in 2 dimensional 2, 1 dimensional array containg 3 element each.

Karthi said:   1 decade ago
I didn't understand this.

Please give explanation in easiest way.

Vijay said:   1 decade ago
Hi karthi.

Just assume it as cube structure having X, Y, Z axes.

Pallavi said:   1 decade ago
Thanks a lot sriram. Your explanation was good.

Biswajit said:   1 decade ago
Thanks sriram. Nice explation

Ramya said:   1 decade ago
Need more clear answer.

Alisha said:   1 decade ago
Here a ,*a,and **a are same .....they return starting address of the array.
***a means that a[0][0][0]. so it returns the value 1.


Post your comments here:

Your comments will be displayed after verification.