When I use the constant argument of a function as a array size in C++ it gives “Constant expression required” error:

So the compiler is not considering m as a constant object, this means I can change the value of m inside the function, but when I try to increment the value of m it gives “cannot modify a const object” error:

It is really ambiguous to me. Can anyone please explain what I’m getting wrong?
constdoesn’t actually mean “this value is constant”, but, “you cannot change this value.”With this, it should be clear why the latter code fails to compile but the former cannot. Even though you give it a default of
5, that doesn’t guarantee it’s five, and so you don’t have a constant, so you can’t make an array. But the type is stillconst, so you can’t change it.That said, since C99 you can have variable-length arrays so this would actually be fine. (It is not okay in C++.) Your compiler just seems to be too old to support C99. (I highly recommend using the latest GCC.)