开发者

Dynamic memory allocation - default-initialization of primitive types in c++

开发者 https://www.devze.com 2023-03-09 12:09 出处:网络
If I allocate an array of some primitive type e.g. double *v = new double[10]; I need to know, what the inital value of the array entries will be.

If I allocate an array of some primitive type e.g.

double *v = new double[10];

I need to know, what the inital value of the array entries will be.

Is it specified in the standard or compiler dependend and where can I find it.

开发者_如何学GoThanks, Johannes


No, the array contents are not initialized. You need to use double *v = new double[10](); to have the default value of 0 for each element (Notice ()).

0

精彩评论

暂无评论...
验证码 换一张
取 消