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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -