Can I really initialize an array with round brackets?

限于喜欢 提交于 2019-12-05 08:17:04

It's a single char with the numerical value of a, in this case 10. Pointers don't only point to arrays, y'know.

You're allocating a single char and assigning it a value from a. It's not allocating an array at all.

It's the same as calling the constructor in a new expression for any other type:

std::string* s = new std::string("foo");
int* i = new int(10);
std::vector<std::string>* v = new std::vector<std::string>(5, "foo");

char t(a) creates a local char initialized to the value of a.
new char (a) creates a dynamically allocated char initialized to the value of a.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!