Possible Duplicate:
Can a local variable's memory be accessed outside its scope?
I recently came across the following code:
#include <stdio.h>
int* abc () {
int a[3] = {1,10,100};
return a;
}
int* xyz () {
int b[1] = {222};
return b;
}
int main() {
int *a, *b;
a = abc();
b = xyz();
printf("%d\n", *a);
return 0;
}
the output is 222
. 'a'
is pointing to the array declared inside the xyz()
.
my question is:
why is a pointing to the array declared inside
xyz()
.the array declared inside the function
xyz()
should go out of scope after the execution of the function. why is that not happening ?