c - Why should a function not return a local array? -
this question has answer here:
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
Post a Comment