I know this is bad:
int * f1(){
int j;
j=100;
return &j;
}
When f1 returns, the memory taken by j may or may not be reclaimed, which is bad.
But is this bad?
void f2(){
int j;
f3(&j);
return;
}
void f3(int * ptr){
printf("%d\n", *ptr);
}
I would say the contents of j will still be preserved since f2 hasn't yet returned. Can anyone confirm this, please? Thanks!
int * f1(){
int j;
j=100;
return &j;
}
When f1 returns, the memory taken by j may or may not be reclaimed, which is bad.
But is this bad?
void f2(){
int j;
f3(&j);
return;
}
void f3(int * ptr){
printf("%d\n", *ptr);
}
I would say the contents of j will still be preserved since f2 hasn't yet returned. Can anyone confirm this, please? Thanks!