returning a local variable from function in C [duplicate]
问题 This question already has answers here : How to access a local variable from a different function using pointers? (9 answers) Closed 2 years ago . #include <stdio.h> int foo1(void) { int p; p = 99; return p; } char *foo2(void) { char buffer[] = \"test_123\"; return buffer; } int *foo3(void) { int t[3] = {1,2,3}; return t; } int main(void) { int *p; char *s; printf(\"foo1: %d\\n\", foo1()); printf(\"foo2: %s\\n\", foo2()); printf(\"foo3: %d, %d, %d\\n\", p[0], p[1], p[2]); return 0; } When I