#include
#include
intmain()
{
int*p;
//p=(int*)malloc(sizeof(int));
*p=5;
printf("%p%d\n",p,*p);
//free(p);
//*p=6;
//printf("%p%d\n",p,*p);
return0;
}
提示p没有初始化,没有任何输出
而下面程序执行得到合理的结果
#include
#include
intmain()
{
int*p;
p=(int*)malloc(sizeof(int));
*p=5;
printf("%p%d\n",p,*p);
free(p);
//*p=6;
printf("%p%d\n",p,*p);
return0;
}
0x55e7822282a05
0x55e7822282a00
但是下面程序释放了申请了内存为什么*P还会被赋值6?
#include
#include
intmain()
{
int*p;
p=(int*)malloc(sizeof(int));
*p=5;
printf("%p%d\n",p,*p);
free(p);
*p=6;
printf("%p%d\n",p,*p);
return0;
}
0x55e5857e22a05
0x55e5857e22a06
分 -->
|