A trivial XOR doubt in a program

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?

The short answer - it is an undefined operation. Means that the C standard regards this as garbage, and your compiler was polite enough to produce spaces.
The reason: there are no sequence points in the line between important steps.

A ; character creates a sequence point. So the first version works. This means the compiler can do any of those calculations in any order...

By the way, that 'swap' algorithm in general is a bad idea; it has unsafe properties. You should use a temp variable. It may look cool to you, but that is about it.