Creating and using arrays
In C, once you create an array, the type and size must be declared, and those values are immutable. In other w...
For further actions, you may consider blocking this person and/or reporting abuse
Very useful! Assigning by index was news to me.
I think both of those float array comments have too many elements, no?
and
I think this bit is a little misleading:
That is true, if some/any of the elements are assigned. But if the local array is only declared, like
the values are garbage. On the other hand, if the array is declared globally outside of all functions, the values actually are implicitly initialized to 0 even if no value is assigned.
I just learned that there is a very naughty non-standard way to do that like this:
where you give a range of indices and the value you want to set those to.
But not all compilers support it, and ISO C forbids it, so probably better not to get used to it and just use loops like you said.
Huh, TIL
float myArray[4] = {[2] = 500.5, [1] = 300.0, [0] = 100.0};
. Good to know, thanks for the write-up.