C++ new malloc realloc

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,并添加存储空间;

posted @ 2018-03-04 08:30  zhchoutai  阅读(460)  评论(0)    收藏  举报