[Error] array must be initialized with a brace-enclosed initializer

[Error] array must be initialized with a brace-enclosed initializer

数组的初始化错误,以下两种为常见错误:

特别是第二种,编译器并不会把“  \0 ”当成一个字符,而是会把它当成它当成 ‘ \ ’ 和 ' 0 ' 两个字符

char arr[10] = '\0';
char arr[10] = "\0";

 正确初始化:

char arr[10] = {'\0'};
char arr[10] = {'s'};

你可能感兴趣的:(c语言)