1,790 views
0 votes
0 votes
#include<stdio.h>
int f(int x,int *py,int **ppz){
  int y,z;
  **ppz+=1;
  z=**ppz;
  *py+=2;
  y=*py;
  x+=3;
  return(x+y+z);
}

void main(){
  int c,*b,**a;
  c=4;
  b=&c;
  a=&b;
  printf("%d",f(&c,b,a));
  return 0;
}

 

Here why doesn't the value of x increment even though the pointers are changed by value?

Why is the answer 19 and not 22?

2 Answers

0 votes
0 votes
the answer is 19 because we are passing the address of c  but there is no pointer in the formal argument it is just declared as a variable  x.so in the called function code works as

ppz and py are the pointer which  will be pointing to c only.

z=5

y=7

x=7

so sum will be 19
0 votes
0 votes
In function call you use &c I think that is wrong if you use only 'c' in that place then ans will be 19

(5+7+7)=19

Here &c calls the address of the c variable and we want to use it as formal argument to copy value of c to x only so use f(c,b,a)

Related questions

1 votes
1 votes
0 answers
1
1 votes
1 votes
1 answer
3
Human asked Oct 8, 2018
624 views
how the answer is 23699?For column major order I get answer as 80039.Even if i go by row major order the answer I get is 23599
2 votes
2 votes
1 answer
4
Ravi kumar singh asked Jan 19, 2018
449 views
Let A be an array with 5 rows and 10 columns. Assume base address is 100 and each element requires 4 bytes. Find the address of A [4,9], if array is stored in row major o...