4 ms·
You may be interested to contrast how it works in python with C. If you have something like int * bar() { int d[2] = {1,2}; return d;} When you comp
by version_five 4y ago
You may be interested to contrast how it works in python with C. If you have something like
int * bar() {
int d[2] = {1,2};
return d;}
When you compile with gcc you get
foo.c: In function ‘bar’:
foo.c:4:8: warning: function returns address of local variable [-Wreturn-local-addr]
This is the behavior it seems like you were expecting, where the array is stored on the stack and so a pointer is invalid once the function ends.