C Programming - Pointers - Discussion
Discussion Forum : Pointers - Point Out Correct Statements (Q.No. 4)
4.
In the following program add a statement in the function fun() such that address of a gets stored in j?
#include<stdio.h>
int main()
{
int *j;
void fun(int**);
fun(&j);
return 0;
}
void fun(int **k)
{
int a=10;
/* Add a statement here */
}
Discussion:
19 comments Page 2 of 2.
Priya said:
8 years ago
Because a is only the name of the variable at which actual value is stored i.e. 10.
And to access 10 from a location we use its address in this fun i.e &a.
And to access 10 from a location we use its address in this fun i.e &a.
Chinnasamy said:
1 decade ago
any one explain this....
Shruti said:
9 years ago
What is the difference between **k & *k?
Ted said:
1 decade ago
But there is no semicolon after the statement in the answer?
Meghali said:
1 decade ago
&J=**K
So, j=*K
We are assigning address of a to j.
So , J=&a
i.e *k=&a
So, j=*K
We are assigning address of a to j.
So , J=&a
i.e *k=&a
Heena said:
1 decade ago
Thanks pavan.
PAVAN said:
1 decade ago
AFTER DUNC CALL,
&J=**K;
J=*K;
IN FUNC FUN,
*K=&A;
SO,
J=&A;
SO ADDRESS OF A IS IN J
&J=**K;
J=*K;
IN FUNC FUN,
*K=&A;
SO,
J=&A;
SO ADDRESS OF A IS IN J
Prabhu said:
1 decade ago
By passing &j as argument,k has the address of j. *k is the value stored at j.so assignment statement *k=&a, stores address of a as value of j.
Deepti said:
1 decade ago
Its normal pointer assignment, whn fun is called its received as k, so whatever operation performed on k will be returned at j in main.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers