When we run this piece of code, it works normally and prints string constant
on the screen:
char *someFun(){
char *temp = "string constant";
return temp;
}
int main(){
puts(someFun());
}
But when we run the following similar code, it won't work and print some garbage on screen:
char *someFun1(){
char temp[ ] = "string";
return temp;
}
int main(){
puts(someFun1());
}
What is the reason behind it? Essentially, both functions do similar things (i.e. return a "string"), but still they behave differently. Why is that?