理解概念嘗試下面的代碼:的免費
#include<stdio.h>
int main()
{
int *p,*q;
p = (int *)malloc(sizeof(int));
*p =10;
q = p;
printf("%u \n",p);
printf("%u \n",q);
free(p);
printf("%u \n",p);
return 0;
}
輸出得到如下:
[[email protected] Tazim]# ./a.out
154804232
154804232
154804232
爲什麼裏面p該地址仍然是印刷,即使我做了free(p);
? free(p)
做了什麼?
我想明白地理解free/malloc的概念。任何幫助都是有價值的。
這是真的,但打印指針值仍然是未定義的行爲 - http://stackoverflow.com/q/4076563/57428 – sharptooth 2011-03-21 12:06:38
@sharptooth - 謝謝。不知道 – MByD 2011-03-21 12:11:58