力扣中为什么不能给数组赋初值?

img


力扣中为什么不能给数组赋初值?力扣中为什么不能给数组赋初值?

我想应该是这样的,sorted[m+n] 是一个可变的数组,如果m+n等于0,那数组是不是会报错呀!虽然不会出现这种情况,你把那行代码直接改成这样试试。
int sorted[m+n];

数组的长度是不可变的,数组的空括号里的必须是常量,你写了个变量的表达式就会报错

因为C99标准里明确规定了初始化语句不能用来初始化变长数组。

6.7.8 Intialization

...
3 The type of the entity to be initialized shall be an array of unknown size or an object type that is not a variable length array type.

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf