What will be the output of following C program? [duplicate]
问题 This question already has answers here : Can a local variable's memory be accessed outside its scope? (20 answers) Closed 5 years ago . char *getString() { char str[] = "Will I be printed?"; return str; } int main() { printf("%s", getString()); getchar(); } Shouldn't the output be "Will I be printed?" ? Instead, the output is coming out to be some garbage value. Why is it so? 回答1: char str[] = "Will I be printed?"; is a local declaration. It is limited with in the function getString() . when