C++:char数组初始化

技术博客 (331) 2023-09-16 10:32:10

char s[10] = "Hello";  // 剩余全用0填充
char s[10] = {'H','e','l','l','o','\0'}; //和上面效果一样
char s[10] = {'H','e','l','l','o'}; // 和前面效果一样
char s[10] = {0} // 全部初始化为0
char s[10] = "Hello, world.\n"; // 超出部分丢弃,没有字符串结尾符
char s[] = "Hello, world.\n";  // sizeof = strlen + 1
THE END

发表回复