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 6 of 6.
Anjaliraj said:
6 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.
Rishab said:
4 years ago
@All.
Suppose if you have an array a[10]
And you want to give a[5] = 12.
You can write *(a+i) = 12 (this is nothing but a pointer way of using array)
if you print(a) it will point to the base address of the array.
these are the basics of array.
Now let's work with the question.
if we have 3d array a[10][10][10].
and you want to make a[5][6][7] = 30,
You can use *(*(*(a+5)+6)+7) = 30,
count the stars needed to give the value. 3 stars,
so until 3 stars you will be printing the address
in this case.
"a"
will print address of a
"*a"
will print address of *(a+0) which is same as a
"**a"
will print address of *(*(a+0)+0) which is same as a
but
"***a"
will print VALUE of *(*(*(a+0)+0)+0) which is 1
Hope you all get it.
Suppose if you have an array a[10]
And you want to give a[5] = 12.
You can write *(a+i) = 12 (this is nothing but a pointer way of using array)
if you print(a) it will point to the base address of the array.
these are the basics of array.
Now let's work with the question.
if we have 3d array a[10][10][10].
and you want to make a[5][6][7] = 30,
You can use *(*(*(a+5)+6)+7) = 30,
count the stars needed to give the value. 3 stars,
so until 3 stars you will be printing the address
in this case.
"a"
will print address of a
"*a"
will print address of *(a+0) which is same as a
"**a"
will print address of *(*(a+0)+0) which is same as a
but
"***a"
will print VALUE of *(*(*(a+0)+0)+0) which is 1
Hope you all get it.
(11)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers