您的位置:首页 > 其它

使用malloc分别分配2KB的空间,然后用realloc调整为6KB的内存空间,打印指针地址

2017-06-06 18:48 573 查看
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#include<malloc.h>

int main(void)

{

int *str1 = NULL;

int *str2 = NULL;

str1 = (int*)malloc(2*1024*sizeof(char));

if(str1==NULL)

{

printf("malloc error!\n");

return -1;

}

printf("malloc: %p\n", str1);

str2 = (int*)realloc(str1,6*1024*sizeof(char));

if(str2==NULL)

{

printf("realloc error!\n");

return -1;

}

printf("realloc: %p\n",str2);

free(str2);

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐