Return a pointer to a variable declared inside the function (basic question)
** sorry, this is a basic question, but couldn't find the answer on Google **
In the following code, is it guaranteed that the "number" variable will point to the same value as assigned in the "f" function? Because I have the idea that "n" will be destroyed, so "i" will point to a random place, but when I run this code, it prints the right value.
Code:
#include <stdio.h>
int *f() {
int *i;
int n = 15;
i = &n;
return i;
}
int main() {
int *number;
number = f();
printf("%d", *number);
return 0;
}