I have stumbled upon a program behaviour that I couldn't understand:
int* g(int i)
{
i = 1;
return &i;
}
void main() {
int* j = g(5);
printf("%d", *j);
}
I used to think that the parameter, i , that was recieved in function g would be deallocated from the stack after g is done. For some reason, the memory isn't deallocated and j holds the value of 5 when printf is called. What is the reason for this?