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.

Preety said:   1 decade ago
Is this problem also have any link with format specifier or its jst with dimension of array?

Naveena said:   1 decade ago
I just tried executing this pgm for gnu compiler, it does not depend on the format specifier.

printf("%u, %u, %d, %d\n", a, *a, **a, ***a);

Also gives the same output.

Vignesh said:   1 decade ago
Starting address of each array is 1002 in printf the format specifier is a %U thats why it print address of that array.

Vasavi said:   1 decade ago
*a means value, right. So *a=1 have to print. But why here *a=1002 is printed? any one explain me clear.

Mahendra said:   1 decade ago
a[i][j][k] is nothing but *(*(*(a+i)+j)+k).

Where 'a' is the base address of the 3D array.

Hareesh said:   10 years ago
Can't understand please explain?

Praveena said:   10 years ago
Thanks, @Alisha. Nice explanation.

Student said:   9 years ago
@Chetan.

Good job, Thank you.

Sowmya said:   9 years ago
*a actually returns the value but how come it returns address? Can anyone explain?

Sagar said:   9 years ago
(*(*(*a+i)+j)+k)
*a=a+0
**a=(*(*a+0)+0)
***a=*(*(*(a+0)+0)+0)

So we are not moving the pointer anywhere.


Post your comments here:

Your comments will be displayed after verification.