The first piece of code is:
#include <stdio.h> char *getString() { char *str = "Will I be printed?"; return str; } int main() { printf("%s", getString()); }
And the second piece of code is:
#include <stdio.h> char *getString() { char str[] = "Will I be printed?"; return str; } int main() { printf("%s", getString()); }
In both of the above codes,char pointer is returned which points to a local variable which could get overwritten but still code-1 manages to run successfully while code-2 print Garbage values.