Home > Back-end > A simple c + + function, can not find the error reason
A simple c + + function, can not find the error reason
Time:10-03
Function is to find and return to the maximum and set it as INT_MIN
CodePudding user response:
Hand slide to choose the wrong Posting area
CodePudding user response:
Program to warning you, you don't initialize index, if the logic problems did not enter the FOR assignment, could have all sorts of strange bugs, because crossing the line, this is your problem, the compiler not mistaken, see error message,
CodePudding user response:
According to the prompt, because the index is not initialized, you can define the alignment index initialization,
In addition, the index as the index of array arr, best for judging index, prevent the index values are not normally lead to array access error, such as the index is not initialized, its value is uncertain, if if has not perform within the for loop, cause the index value is not updated, then to the array arr index is uncertain, if the index & lt; 0, or index & gt; The length of the array arr, the array access will make a mistake, the program crashes