// 可省略(=)
double earnings[4] {1.2e4, 1.6e4, 1.1e4, 1.7e4}; // okay with C++11
// {} 内可不包含任何东西,默认全为0
unsigned int counts[10] = {}; // all elements set to 0
float balances[100] {};
// 列表初始化禁止缩窄转换
// long plifs[10] = {23, 34, 3.0}; // error: narrowing conversion of '3.0e+0' from 'double' to 'long int'
// char slifs[4] {'h', 'i', 1122011, '\0'}; // error: narrowing conversion of '1122011' from 'int' to 'char'
char tlifs[4] {'h','i', 112, '\0'};
C++11数组初始化方法
最新推荐文章于 2022-10-28 18:51:45 发布