I am studying about stack and the teacher gave me this example,
and this program gave this output :Code://stacktest.c #include <stdio.h> void f(int **p){ int x = 1; printf("&x=%p\n",&x); *p = &x; } void g(void){ int a = 123; printf("&a=%p\n",&a); } int main(void){ int *p; f(&p); g(); printf("*p=%d\n",*p); return 0; }
here, the pointer p gave the value of a (=123) variable instead of x (=1), I didnt get the explanation so clearly.Code:&x=0xbffff758 &a=0xbffff758 *p=123
so, anyone?