本帖最后由 罗冠坤 于 2014-3-25 12:44 编辑
- int main(void) {
- int *pnumber = malloc(100);
-
- if (!pnumber) {
- printf("动态分配内存失败");
- return 1;
- }
-
- int number = 10;
-
- pnumber = &number;
-
- printf("%d\n",++*pnumber);
-
- free(pnumber);
- pnumber = NULL;
-
- return 0;
- }
复制代码
上面的代码报错:
*** error for object 0x7fff54d80bcc: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
不知道哪里写错了,错误的意思好像是在释放动态分配内存时出错。但是没有看出来哪里错了。 |