Compiler Explorer Example: https://godbolt.org/z/AEv4Ci
This code
int main() {
const int Size = 16; <-- const
int arr1[Size];
int arr2[Size];
int arr3[Size];
for (auto I = 0; I < Size; ++I) {
arr3[I] = arr1[I] + arr2[I];
}
return arr3[Size - 1];
}
returns 0
but this code:
int main() {
int Size = 16; // <-- not const
int arr1[Size];
int arr2[Size];
int arr3[Size];
for (auto I = 0; I < Size; ++I) {
arr3[I] = arr1[I] + arr2[I];
}
return arr3[Size - 1];
}
returns a random number