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

Ankita said:   8 years ago
a, *a, **a have format specifiers as "%u" which tells the compiler to print the address at a[0]. So, it prints 1002 thrice, each for a, *a, **a.

However, for ***a, the format specifier is "%d" which tells the compiler to print the value at that particular address. So it prints 1 for ***a.

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.

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.

Uttam raj said:   1 decade ago
I didn't the answer but when i execute the is completely different from the options..... when i execute the answer i got is
(3209883548, 3209883548, 3209883548, 1).....how this is possible

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.

Kishor said:   1 decade ago
We have to pay attention towards specific format used.

To get address printed we use "%u" and for value at address "%d" is used.

Thats how given n programme.

Rohan said:   7 years ago
@Ashu, @Payal.

printf("%u, %u, %u, %d\n", a, *a, **a, ***a);
/* It specifies %d that's why the data stored in ***a is printed instead of its address.... */.

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.

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.

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.