1
My show was exhibiting some weird behavior, until I found out that there was a bang of array, for example:
int arr[3];
for (int i = 0; i<10; i++) {
arr[i]=i;
cout << arr[i];
}
In this clear example, i
exceeds the limit of only 3 elements of array.
However C++ does not warn anything and the program will literally detonate the memory, generating unpredictable behaviors in the program.
How C++ can be made to warn (and avoid) when this occurs?
Just like @Maniero said, it’s best to use a built in iterator or compare to the array size.
– lazyFox