c - Why should a function not return a local array? -


char* f() { char s[100]; //....function body code return s; } 

why should not written this?

s local variable exists within function.

once function exits, s no longer exists, , memory re-allocated other parts of program.

therefore, function returning pointer random meaningless block of memory.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -