Hi,
I am trying to reverse a string using the following program utilizing the Exclusive OR bit operation:
int main() {
char str[] = "Quraish";
char *p = str, temp;
char *q = str + strlen(str) - 1;
while ( p != q ) {
if (*p != *q) {
*p ^= *q; *q ^= *p; *p ^= *q;
}
p++; q--;
}
printf("%s \n", str);
}
The above code works perfectly alright, but if I change the line
*p ^= *q; *q ^= *p; *p ^= *q;
to
*p ^= *q ^= *p ^= *q;
(I am trying to do swapping inline)
it prints an empty string. Could anyone tell me why this behaviour is?