Arrays & constants

In good coding practice, how are named constants and arrays related? Why is this good?
Assuming that having named constants and arrays related is a good thing, it means that you can see which constant refers to which array:
1
2
3
4
5
6
7
8
9
10
11
const int SIZEA = 20;
const int SIZEB = 10;

int vals[SIZEA];
int keys[SIZEB];

// 800 LOC later...

for (int i = 0; i < SIZEA; ++i) {
    keys[i] = i; // why does it crash here?
}


Of course, in 'actual' good coding practice, you'd use a std::vector or std::array instead:
1
2
3
4
5
6
7
8
std::array<int, 20> vals;
std::array<int, 10> keys;

// 800 LOC later...

for (int i = 0; i < keys.size(); ++i) {
    keys[i] = i;
}
Last edited on
thanks
Topic archived. No new replies allowed.