Possible Duplicate:
Can a local variable's memory be accessed outside its scope?
Scope vs life of variable in C
int *p;
void foo()
{
int i = 5;
p = &i;
}
void foo1()
{
printf("%d\n", *p);
}
int main()
{
foo();
foo1();
return 0;
}
Output: 5 (foo1() print the value of i)
Note: I am running this program on Linux
According my knowledge, the scope of local automic variables are limited to the life of block/function.
- In what memory segment this variable i in foo() gets store? or where does all local variables of functions get stores?
- How can I access this from another function?