1 votes 1 votes #include <stdio.h> void f(int x,int *p) { *p=x; x=10; } int main() { int a=5,b=6; int *p=&a,**q; *p=20; q=&p; f(a,&b); *q=&b; *p=30; printf("%d",b); } How the answer is 30 I am getting 20? reena_kandari asked Jan 24, 2017 reena_kandari 1.2k views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 4 votes 4 votes See last 3 lines of main() function q is pointing to p *q = &b implies that now p is pointing to b *p= 30 Implies contents of variable b now modified to 30 G.K.T answered Jan 24, 2017 • selected Jan 24, 2017 by reena_kandari G.K.T comment Share Follow See all 3 Comments See all 3 3 Comments reply vishwa ratna commented Jan 24, 2017 reply Follow Share there is a function call in between , so you are saying wrong. anyways still the answer has to be 30 , but i am confused how. 0 votes 0 votes G.K.T commented Jan 24, 2017 reply Follow Share Surely theres a func call but final value of b is decided by last 3 lines only. See, 20 and address of b is passed Now, in function f x=20 and p is pointing to b *p=x Implies that now b is modified with value if x i-e 20 Now return to main *q= &b q pointing to p so *q means p p=&b So now p points to b And *p=30 Means b value is modified to 30. Now tell at which point your are confusing? 0 votes 0 votes vishwa ratna commented Jan 25, 2017 reply Follow Share I got it bro... It was clever though ! Thanks!! 0 votes 0 votes Please log in or register to add a comment.