ALO*_*low 3 c malloc free memory-management
因为我已经做了一些C而且我必须刷新对指针的理解,这需要一段时间.这是一个修改指针内容的函数.问题是这段代码是否正确.如果我只释放指针或者我必须释放指针的内容就足够了
void foo(char **str) {
// str has been allocated enough bytes for the following text
*str = "allocate some text";
}
int main(int arc, char *argv[]) {
char *someString;
foo(&someString);
free(someString); // is this the correct place to free
}
Run Code Online (Sandbox Code Playgroud)
谢谢.