573 views

3 Answers

1 votes
1 votes

1000 20 1000

will be the output

the address of p is 1000 which is passed to fun function .

**q is a pointer to pointer so at position 2000(address of q)will contain

1000

**q=r,will modify the value of position pointed by p,therefore *p will become 20

and as address of p is 1000,1000 will be printed

edited by
1 votes
1 votes

              

First diagram from Left to right shows the initial case in which value of *q is printed which is 1000 

the in second diagram *q got changed to 20 and pointing to r in diagram you can see that this value of *q going to be returned to main and finally 20 got printed by main printf and at last 1000 will be printed which is same as it were before  1000.

so output will be 1000 , 20 ,1000

0 votes
0 votes

                          Content                                                                  Address

p                       4000 //assume malloc return 4000                       1000  //given

4000                 50

fun(&p)  ==>fun(1000)

q                       1000                                                                    2000 //given

r                         20

**q=r will make 

4000                  20

so printf("%u",*q) will output content at memory content of q i.e. 4000

&printf("%d %u",*p,p) will output value at memory content of p and memory content of p respectively i.e. 20 4000

Related questions

0 votes
0 votes
0 answers
1
pC asked Sep 7, 2018
534 views
#include <stdio.h>int main(void) { int i=10; printf(" %d %d %d",i==10,i=40,i>15 );} Conceptsundefined behaviorfloating point representation
1 votes
1 votes
3 answers
3
just_bhavana asked Jun 23, 2017
1,232 views
#include <stdio.h void f(int); int main() { int a=4; f(a); return 0; } void f(int n) { if(n>0) { f( n); printf("%d", n); f( n); } }Explain how function calls take place
2 votes
2 votes
1 answer
4
Akriti sood asked Jan 23, 2017
264 views
will there be no compile time error as we are initialising array greater than its size??