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

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -