我想知道使用 malloc 和 free 的正确/标准方式是什么。free后是否需要设置指针NULL?基本上,以下两种方式哪一种是正确的?
double* myPtr = (double*)malloc(sizeof(double)*5);
.....
free(myPtr);
或者
double* myPtr = (double*)malloc(sizeof(double)*5);
.....
free(myPtr);
myPtr = NULL;
或者应该是其他方式使用malloc和free?谢谢。