char* GetMemory2(void) { char p[]="hello word"; return p; } void PrintString(void) { char* str = NULL; str = GetMemory2(); printf(str); }
#include<iostream> using namespace std; char* GetMemory2() { char p[] = "hello word"; return p; } int main() { char* str ; str = GetMemory2(); cout<<str[4]; } //输出o,这道题答案不是瞎扯呢么 //指针指向的内存当然由指针才能释放,函数返回是不能释放指针指向的内存的, //所以str指向的内存才会继续存在
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题