If you declare an array outside a function at file scope, it will then get static storage duration. All variables with static storage duration must have compile-time constants as initializers and if they are arrays, the array sizes must also be compile-time constants.
This means that the size has to be something like an integer constant 123 or an expression containing only integer constants.
The const keyword, non-intuitively, does not make something a compile-time constant, it only makes something read-only. C and C++ are different here, you code would work in C++.
Possible solutions:
- Move
students_grades_db inside a function. Then you can declare array sizes using any kind of expression, including common int variables. You probably shouldn't declare that array as "global" anyhow.
- Or swap out your constants for
#define number_students 4.
constvariables not constant variables. C does not not have constant variables (C++ has constexpr which can give named constant expressions).