I run the following code
int *pointer;
void fun1() {
int i;
pointer = &i;
*pointer = 11;
}
void fun2() {
printf("\nFun 2: Hello World\n");
}
int main() {
pointer = (int*) malloc(sizeof(int));
*pointer = 0;
fun1();
printf("%d\n",*pointer);
fun2();
printf("%d\n",*pointer);
return 0;
}
And the output is
11
Fun 2: Hello World
20
I would expect it to be 11 instead of 20. What am I missing?
Thanks.