For the first time today, I felt deeply about the array out-of-bounds problem. If the array out-of-bounds is run in the release version, no error is reported. If it is a debug version, if you reference the array subscript directly by a constant value, the array is detected to be out of bounds. If you reference the array subscript through a variable, the array subscript will not be detected !!!
Test the following code,
1 # include <stdio. h> 2 3 int main (void) 4 {5 Int arr [1] [1] = {20}, BRR [1] = {1}, y = 5; 6 7 // printf ("% d \ n", arr [5] [0] = 0); // In the debug version, directly referencing the array subscript with constants will be detected by vs2010 when the array is out of bounds 8 printf ("% d \ n", arr [y] [0] = 10 ); // No error is reported in the debug version. If the array subscript is referenced by a variable, it will not be detected if the subscript is out of the range !!! 9 // printf ("% d \ n", BRR [5] = 0); // In the debug version, directly referencing the array subscript with a constant will be detected by vs2010 that the array is out of bounds 10 printf ("% d \ n", BRR [y]); // No error is reported in the debug version, if the array subscript is referenced by a variable, it will not be detected if it is out of the range !!! 11 12 Return 0; 13}
Run in the release version. The arrays in the four printf versions are out of bounds, but vs2010 directly releases them.
At this time, vs2010 will not detect cross-border issues!
Run the following command in debug:
The test results of the debug version are also very small, and the array subscript can be referenced as a variable to allow direct access:
It seems that you should always pay attention to this problem in your mind. Otherwise, when the array crosses the border, you can only get dizzy when looking at the inexplicable output of the program!
Beware of array out-of-bounds!