举个简单的例子. #include <iostream> #include <malloc.h> using namespace std; char* get_str() { char *buffer = new char[20]; memset(buffer, 0, _msize(buffer)); strcpy(buffer, "hello world!"); return buffer; } int main(int argc, char** argv) { char *ptr = get_str(); cout << ptr << endl; delete ptr; ptr = NULL; return 0; }