The first way is generally better, since it zero initializes all
members. Memsetting to 0 is not always the same as zero initializing,
particularly for floating point and pointer members, which may have 0
members. Memsetting to 0 is not always the same as zero initializing,
particularly for floating point and pointer members, which may have 0
values that aren't all bits zero.
Nope, remaining members are value-initialized, which for built-ins
means initialized to 0. You can also do:
MYSTRUCT myStruct = {};
to get the same effect.
本文探讨了在编程中初始化成员时,零初始化与设置为零之间的区别,特别是针对浮点数和指针成员。零初始化通常提供更一致且安全的初始化方式。
15万+

被折叠的 条评论
为什么被折叠?



