基于C++初始化数组版本和编译器
In C++11 or higher regardless of compiler int myArray[10] = { 0 };
would initialize to all elements to zero.问题是,这也可以在C ++ 98中起作用,并且编译器是否可以决定将所有元素初始化为零?换句话说,用给定编译器的C ++ 98可以忽略所有元素的零分配吗?
我找到了此页面: https://en.cppreferent /Zero_Initialization 列出了C ++ 98关于零初始化的缺陷。
In C++11 or higher regardless of compiler int myArray[10] = { 0 };
would initialize to all elements to zero. The question is would this also work in C++98 and could the compiler not decide to initialize all elements to zero? In other words could C++98 with a given compiler ignore the assigning zero to all elements?
I found this page: https://en.cppreference.com/w/cpp/language/zero_initialization which lists C++98 defects about zero initialization.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有元素均为零。 C ++的引号98:
与从C ++ 03开始的含义相比,默认初始化的含义在C ++ 98中截然不同,在C ++ 03中,旧的默认初始化本质上是重新命名的值初始化,而新的默认初始化变成了“无初始化”的意思。
请注意,
int myarray [10] = {};
将实现相同的目标。不必明确地为第一个元素提供值。All elements would be zero. Quotes from C++98:
The meaning of default initialisation was radically different in C++98 compared to its meaning starting from C++03 where the old default initialisation essentially was renamed value initialisation and the new default initialisation became to mean "no initialisation" for trivial types.
Note that
int myArray[10] = {};
would achieve the same goal. It's unnecessary to explicitly provide a value for the first element.