Swapping alternate digits of a number

a[i]^=a[j]^=a[i]^=a[j];

You’re attempting to read and write both a[i] and a[j] in a single expression without a sequence point. Doing so invokes undefined behavior.

Break up the expression into multiple lines.

a[i]^=a[j];
a[j]^=a[i];
a[i]^=a[j];

Leave a Comment