int* p = new int[5](); 与 int* q = new int[5]; 的区别

来源:互联网 发布:veket linux.iso 编辑:程序博客网 时间:2024/05/24 20:06

/*That's not quite true (you should almost certainly get yourself an alternative reference), you are allowed an empty initializer (()) which will value-initialize the array but yes, you can't initialize array elements individually when using array new. */

//动态申请数组

int* p = new int[5](); // array initialized to all zero
int* q = new int[5];   // array elements all have indeterminate value


/*There's no fundamental reason not to allow a more complicated initializer it's just that C++03 didn't have a grammar construct for it. In the next version of C++ you will be able to do something like this.*/
int* p = new int[5] {0, 1, 2, 3, 4};
原创粉丝点击