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;
}
Discussion:
54 comments Page 2 of 6.
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.
Where 'a' is the base address of the 3D array.
Hareesh said:
10 years ago
Can't understand please explain?
Praveena said:
9 years ago
Thanks, @Alisha. Nice explanation.
Student said:
9 years ago
@Chetan.
Good job, Thank you.
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.
*a=a+0
**a=(*(*a+0)+0)
***a=*(*(*(a+0)+0)+0)
So we are not moving the pointer anywhere.
Emanuel said:
9 years ago
I think 1002,1 and after it has no sense.
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.
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.
Ashu said:
8 years ago
Why ***a=1? Please explain it.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers