You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The suggested solution can store an erroneous value in largest or cause undefined behaviour.
Problem:
Incrementing p right after checking p < a+n causes a problem after p is incremented to point to the last element in the array: a+(n-1). After the iteration completes, the condition is checked and because a+(n-1) < a+n is true, the loop proceeds to increment p to point to a + n (out of bounds of the array) and continue the loop, potentially causing undefined behaviour.
Suggested solution:
Change p++ to ++p.
The text was updated successfully, but these errors were encountered:
The suggested solution can store an erroneous value in
largest
or cause undefined behaviour.Problem:
Incrementing
p
right after checkingp < a+n
causes a problem afterp
is incremented to point to the last element in the array:a+(n-1)
. After the iteration completes, the condition is checked and becausea+(n-1) < a+n
is true, the loop proceeds to incrementp
to point toa + n
(out of bounds of the array) and continue the loop, potentially causing undefined behaviour.Suggested solution:
Change
p++
to++p
.The text was updated successfully, but these errors were encountered: