668 views

2 Answers

4 votes
4 votes

given that c is integer ----------> let c stored at memory location 100 with the value 4

given that b is pointer to c ----------> let b stored at memory location 200 with the value 100

given that a is pointer to b ----------> let a stored at memory location 300 with the value 200

therefore c is integer, b is a pointer to integer, a is a pointer to integer pointer...

for accessing value at c you have three methods c, *b, **a

in C, parameters are call by value only.... ===> just copy the values 

f ( int x, int *py, int **pz ) ---- x is integer, py is a pointer and pz is a pointer to integer pointer

x=4, py=100,pz=200

**pz+=1; ===> **pz=**pz+1 ===> **pz = ( (**pz) + (1) )  [ using precedence of operator ]

**pz = ** (200) = * (100) = value at 100,  if it is left side of = operator it is storing the value, else it is right side of = operator it retrieve the value

∴ storing value of (memory address 100) = retrieving value of (memory address 100) + 1 ===> c=c+1 ==> c=4+1 ==> c=5


*py+=2; ===> *py=*py+2 ===> *py = ( (*py) + (1) )  [ using precedence of operator ]

*py = * (100)  = value at 100

∴ storing value of (memory address 100) = retrieving value of (memory address 100) + 2 ===> c=c+2 ==> c=5+2 ==> c=7


x+=3; ===> x=x+3 ===> x = ( (x) + (3) )  [using precedence of operator] ==> x=4+3 ===> x=7


return x+*py+**pz ===> return ( (x)+(*py)+(**pz) ) ===> return ( 7+7+7 ) ===> return (21)

∴ Answer is 21

1 votes
1 votes
answer is 21

variable a is pointer to b and b is pointer to c ,c=4

when we call f(c,b,a) then x=4,py will contain b and ppz will contain c

**ppz+=1 => **ppz=**ppz+1 =>c=c+1 =>c=4+1 =>c=5

*py+=2 =>*py=*py+2 =>c=c+2 =>c=5+2 => 7

x+=3 =>x=x+3 =>x=4+3 =>7

so finally x will contain value 7

we require to find x+*py+**ppz

so x+x+x=3x =>3*7=>21(answer)
edited by

Related questions

3 votes
3 votes
1 answer
1
Storm_907 asked Apr 16, 2023
461 views
Please explain this question void main() { int a =300; char *ptr = (char*) &a ; ptr++; *ptr=2; printf("%d" , a); }
4 votes
4 votes
4 answers
3
Manoj Kumar Pandey asked May 22, 2019
818 views
https://gateoverflow.in/?qa=blob&qa_blobid=14433986388826671915int main() { int a = 10; int *b = &a; scanf("%d",b); printf("%d",a+50); }What will be the Output of the fol...