Why does the last printf output -2
?
Isn't it supposed to output 2
?
Is there an explanation for this?
#include <stdio.h>
void foo(int **);
int main()
{
int x=20;
int *p;
p=&x;
printf("%d\n",&x);
printf("%d\n",p);
printf("%d\n",&p);
foo(&p);
printf("%d\n",p);
printf("main%d\n",*p);
}
void foo(int **p)
{
int j=2;
printf("%d\n",p);
printf("%d\n",*p);
*p=&j;
printf("%d\n",*p);
printf("%d\n",**p);
}