What's the difference between new char[10] and new char(10)

前端 未结 6 1407
迷失自我
迷失自我 2020-12-05 00:06

In C++, what\'s the difference between

char *a = new char[10];

and

char *a = new char(10);

Thanks!

6条回答
  •  眼角桃花
    2020-12-05 00:07

    The first allocates an array of 10 char's. The second allocates one char initialized to 10.

    Or:

    The first should be replaced with std::vector, the second should be placed into a smart pointer.

提交回复
热议问题