This is not allowed because struct
has const
members:
error: assignment of read-only location array[0]
array[0] = e;
When a struct
has one const
member, the whole struct
cannot be assigned as well.
If it were possible to assign array elements like that, one would be able to circumvent const-ness of any member of a struct
like this:
Expected replacement = {.number = array[0].number, .operand = newOperand}; // << Allowed
array[0] = replacement; // <<== This is not allowed
Compiler flags this assignment as an error (demo).
If you need to keep const
, you would have to construct your array with initializers instead of using assignments.