error: function returns address of local variable
问题 I\'m beginner with C and I am learning on my own. I am creating the following function: char *foo(int x){ if(x < 0){ char a[1000]; char b = \"blah\"; x = x - 1; char *c = foo(x); strcpy(a, b); strcat(a, c); return a; } blah ... } I am basically trying to return an appended string, but I get the following error: \"error: function returns address of local variable\", any suggestions, how to fix this? 回答1: The local variables have a lifetime which extends only inside the block in which it is