All it's doing is swapping two entries in an array.
arr[i]
is being set to the current value of arr[i+1]
and at the same time arr[i+1]
is being set to the current value of arr[i]
. It's called multiple assignment or parallel assignment.
So to take your example:
say in this case arr[i] = 1 and arr[i+1] = 3
It's doing arr[i] = 3
and arr[i+1] = 1
at the same time so the values in the array end up swapped.
You could do it in separate statements but you would need to use some temporary variable to hold one of the values otherwise the two values in the array would end up equal. e.g.
temp_value = arr[i]
arr[i] = arr[i+1]
arr[i+1] = temp_value