You cannot blindly substitute one expression with another. Why? Let's look into simpler example:
tmp = currentIndex + 1;
vs
tmp = ++currentIndex;
what is the difference? You will get the same value in tmp
as a result but first expression would not change variable currentIndex
while second one would. So for example you can execute first exression many times with the same result, while second one will give you different result every time.
On another side you need to be careful with changing variable and using it within the same exression - you can easily get Undefined Behavior, as compiler allowed to optimize exressions different way and you do not know when exactly variable would be changed. Detail can be found here
As for this loop:
for (int currentIndex = 0; currentIndex < --length; ++currentIndex)
if it is used in the same loop this seem to be the same mistake as before length - 1
replaced with --length
, the problem is that condition checked every iteration so each time length
would be decreased. But length - 1
simply means you want to iterate once less than size of array, which makes sense as you access array with currentIndex + 1
and do not want to access invalid index. This is pure speculation or educated guess, but without context it is difficult to say for sure.