This is really strange code with undefined behavior. What do you expect this:
int n; // No value!
int str[n];
To do? You get an array whose length is unknown since n
has no value at the point of the str
declaration.
If you expected the compiler to "time-travel" back to the str[n]
line magically when n
is given a value by scanf()
, then ... that's not how Co works, and you should really read up on the language a bit more. And compile with all warnings you can get from your environment.
As an extra detail, even if it were fixed so that n
had a value, the for
loop overruns the array and gives you undefined behavior again.
For an array of size m
, the loop header should read
for (size_t i = 0; i < m; ++i)
Since indexing is 0-based, you cannot index at m
, that's outside the array.