#include char *string(){ char buff[4]="str"; <--- This is stack local storage return buff; } int main() { printf("%s\n", string()); <--when printf is actually called, stack local storage for string goes away. }