0
void f(int pv1, int *pv2, int *pv3, int pv4[]){
  int lv = pv1+ *pv2 + *pv3 + pv4[0];
  pv1= 11;
  *pv2= 22;
  *pv3= 33;
  pv4[0]= lv;
  pv4[1]=44;
 }

int main(void){
  int lv1=1, lv2=2;
  int *lv3;
  int lv4[]= {4,5,6};
  lv3= lv4+2;
  f(lv1, &lv2, lv3 , lv4);
  printf("%i,%i,%i\n", lv1, lv2, *lv3);
  printf("%i,%i,%i\n", lv4[0], lv4[1], lv4[2]);
  return 0;
}

Answer : 1 22 33

I don't understand how.

My working: lv1=1, lv2=2, lv3 = lv4+2= 6, lv4[]= {4,5,6}

After going through f(), Lv1=11, lv2=22, lv3=33, lv4[0]=13 and lv4[1]=44

1 Answers1

1

Nothing is not understandable here.

  • pv1= 11; will not affect value of lv1, because you are just populating a local variable pv1 in f(), not any pointer. pv1 argument is passed by value, and becomes local to f().

  • Values of *lv3 & lv2 are updated with 22 & 33. Because, your updating values in the address using pointers.

jjm
  • 431
  • 3
  • 19