1,402 views

2 Answers

4 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 1 vote
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
Position:
Show:

Related questions

8 8 votes
1 1 answer
283
283 views
GO Classes asked Jun 19
283 views
What is the output of the following code?#include <stdio.h void fun(int a[], int *p) { a = a + 5; *(p + 2) = *(p + 2) + 10; p++; *p = *p + 1; } int main() { int arr[] =...
6 6 votes
1 1 answer
229
229 views
GO Classes asked Jun 19
229 views
What is the output of the following code?#include <stdio.h int main() { int arr[] = {10, 20, 30}; int *p = arr; printf("%d %d", *p, *(arr + 2)); return 0; }$\texttt{10 20...
8 8 votes
1 1 answer
234
234 views
GO Classes asked Jun 6
234 views
What is the output of the following code?#include <stdio.h void change(int *p, int *q) { *p = *p + 4; *q = *p + *q; p = q; *p = *p - 3; } int main() { int a = 6, b = 10; ...
8 8 votes
1 1 answer
239
239 views
GO Classes asked Jun 6
239 views
What is the output of the following code?#include <stdio.h int main() { int a = 8, b = 12; int *p = &a; int *q = &b; *p = *p + *q; q = p; *q = *q - 5; printf("%d %d", a, ...