📜  如何从 C++ 代码示例中的函数返回 char*

📅  最后修改于: 2022-03-11 14:44:54.114000             🧑  作者: Mango

代码示例1
//Function declaration
char* testfunc()
{
    char* str = malloc(10 * sizeof(char));
    return str;
}

//Calling the function
foo = testfunc();
// Do something with your foo
free(foo);        //It is required to free() memory to avoid memory lead