//print the allocated address
printf("The address get by realloc is : %p\n",new_ptr);
//print the 4 integers at the beginning
printf("4 integers at the beginning is:\n");
for (i=0;i<4;i++)
{
printf("%d\n",new_ptr[i]);
}
return 0;
}
运行结果如下:

从上面可以看出,在这个例子中新的空间并不是以原来的空间为基址分配的,而是重新分配了一个大的空间,然后将原来空间的内容拷贝到了新空间的开始部分。
3、三者的联系
calloc(n,size)就相当于malloc(n*size),而realloc(*ptr,size)中,如果ptr为NULL,那么realloc(*ptr,size)就相当于malloc(size)。