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 6 of 6.

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

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.

Sachin said:   1 decade ago
Hi Anusha!

Well 'a' holdes the values, *a is a pointer, **a is a pointer to a pointer and ***a is pointer ro a pointer to a pointer and so on.

Hope you got me. Any how it seems you are fresher don't panic, such questions are not generally asked.

Anusha said:   1 decade ago
Can anyone explain this ? what do *a, **a, ***a mean?


Post your comments here:

Your comments will be displayed after verification.