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 3 of 6.
Shilpa said:
8 years ago
Well done @Sangaraj.
Payal said:
8 years ago
Why ***a=1?
Please explain it.
Please explain it.
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.... */.
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.... */.
Muhammad Fouad said:
7 years ago
Hey guys, just want to figure out some concepts:-
The array name (without a subscript) is a pointer to the first element in the array.
So, when saying printf( "%d, %d, %d and %d", a, *a, **a, ***a );
The first a is a pointer to the first element, i.e returns the address of the array or the first element of the array, the second a is a pointer to a pointer, also returns am address, the third one also the same, but the last one is exceptional, because the compiler already knows that a 3D array was declared, so a maximum of triple dereferencing statements is obtained, because the forth a which is ***a will return the actual value which is 1!!.
Hope you got it.
The array name (without a subscript) is a pointer to the first element in the array.
So, when saying printf( "%d, %d, %d and %d", a, *a, **a, ***a );
The first a is a pointer to the first element, i.e returns the address of the array or the first element of the array, the second a is a pointer to a pointer, also returns am address, the third one also the same, but the last one is exceptional, because the compiler already knows that a 3D array was declared, so a maximum of triple dereferencing statements is obtained, because the forth a which is ***a will return the actual value which is 1!!.
Hope you got it.
Pattu said:
7 years ago
Thanks for the answer @Shriram.
Anjaliraj said:
7 years ago
Thanks for the answer @Sriram.
Ajitesh said:
6 years ago
A gives the address of 3d aray.
3d array a[blocks][rows][columns].
*a gives the address of 1st block (z direction) of the array which is same as the address of a.
**a gives the address of 1st row of 1st block of the array which is same as the address of the 1st block.
***a gives value at address specified by **a.
3d array a[blocks][rows][columns].
*a gives the address of 1st block (z direction) of the array which is same as the address of a.
**a gives the address of 1st row of 1st block of the array which is same as the address of the 1st block.
***a gives value at address specified by **a.
Pushparj Manikam said:
5 years ago
a,*a,**a is base address.
***a is return the value of base address.
***a is return the value of base address.
Venkatesh said:
1 decade ago
@sriram good explanaton I got you dude.
Sachin said:
2 decades 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.
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers