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

前端 未结 6 1425
迷失自我
迷失自我 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:22

    new char[10];
    

    dynamically allocates a char[10] (array of char, length 10), with indeterminate values, while

    new char(10);
    

    again, dynamically allocates a single char, with an integer value of 10.

提交回复
热议问题