It is said that, you should not return value that is created on stack. i.e the auto variable or the local variables. Can anyone tell me how the program below prints the right value "hi"???
char* foo() {
char x[10] ;
strcpy( x, "hi");
return x;
}
int main(){
char *f;
f = foo();
printf( "%s", f);
}
Sorry that my code isn't tagged but I'm in too big a hurry to read http://cboard.cprogramming.com/showthread.php?t=25765