简体   繁体   English

c++中的字符数组初始化为NULL

[英]character array initialisation to NULL in c++

What is the difference between initialising character array as this像这样初始化字符数组有什么区别

char c[10]={0};

and this还有这个

char c[10]="";

char c[10]={0}; guarantees that every element of the array is 0. Note that in C++ you can write char c[10]={};保证数组的每个元素都是 0。请注意,在 C++ 中,您可以编写char c[10]={}; which has the same effect.这具有相同的效果。

char c[10]=""; guarantees that only the first element of the array is 0;保证只有数组的第一个元素为 0; the other elements are uninitialised.其他元素未初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM