从C中的函数返回局部变量
#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;}
gcc -ansi -pedantic -W -Wall
warning: function returns address of local variable
跃然一笑
偶然的你
SMILET