标签:
#include <stdio.h>
#include <stdlib.h>
int main(void){
int* p=NULL; int i;
p = (int *)malloc(6 * sizeof(int));
if (NULL == p) { //判断是否为空
printf("内存分配出错!");
exit(1);
}
for(i=0;i<6;i++) {
p++; //导致内存泄露
*p = i;
printf("add=%d,%2d\n",p, *p);
}
if (NULL != p) { //判断是否为空
free(p); //这句运行时出错
p=NULL;
} return 0;
}
来源:http://c.biancheng.net/cpp/html/2752.html
标签:
原文地址:http://www.cnblogs.com/NCCM/p/4870097.html