下面以一个例子来引出这种错误:
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <string.h>
void func(int *p)
{
p = (int *)malloc(sizeof(int) * 10);
memset(p, 0, sizeof(p));
p[0] = 1;
}
int main()
{
int *p = NULL;
func(p);
cout << p[0] << endl;
return 0;
}
#include <iostream