Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
char* f() { char s[100]; //....function body code return s; }
为什么不应该这样写?
s是只存在于函数内部的局部变量。
s
一旦函数退出,s不再存在,它的内存将重新分配给程序的其他部分。
因此,您的函数返回一个指向随机无意义内存块的指针。