C++ new malloc realloc

来源:互联网 发布:centos web服务器 编辑:程序博客网 时间:2024/06/04 18:18

int* a = new int;          分配了存储空间,但没有赋初值

int* a = new int(10)     分配了存储空间,并赋初值,即*a = 10


int* a = new int[100]      分配了存储空间,但没有赋初值,a为长度为100的数组的首地址

int* a = new int[100]()    分配了存储空间,并将数组清零,a为长度为100的数组的首地址



int* a = (int*)malloc(100*sizeof(int)); 

分配了存储空间,a为长度为100的数组的首地址


int *c = (int*)realloc(a,1000*sizeof(int));

将a的存储空间复制到c,并增加存储空间;

1 0
原创粉丝点击