#include
#include
int main(void) {
int p=NULL;
p=(int)malloc(sizeof(int));
*p=3;
printf("p=%p\n",p);
printf("*p=%d\n",*p);
p=(int*)realloc(p,sizeof(int));
printf("p=%p\n",p);
printf("*p=%d\n",*p);
p=(int*)realloc(p,3*sizeof(int));
printf("p=%p\n",p);
printf("*p=%d\n",*p);
realloc(p,0);
p=NULL;
return 0;
}
#include<iostream>
using namespace std;
int main(void) {
int *p=NULL; //修改
p=(int*)malloc(sizeof(int));//修改
*p=3;
printf("p=%p\n",p);
printf("*p=%d\n",*p);
p=(int*)realloc(p,sizeof(int));
printf("p=%p\n",p);
printf("*p=%d\n",*p);
p=(int*)realloc(p,3*sizeof(int));
printf("p=%p\n",p);
printf("*p=%d\n",*p);
realloc(p,0);
p=NULL;
return 0;
}
運行結果:
p=01017A10
*p=3
p=01017980
*p=3
p=01011A80
*p=3
請按任意鍵繼續. . .