#include <stdio.h>
void fun(char a[]){
a[0]^=a[1]^=a[0]^=a[1];
}
int main(int argc, char **argv){
char b[10];
b[0]='h';
b[1]='j';
fun(b);
printf("%c",b[0]);
return 0;
}
What is wrong with this code. It shall swap the b[0] and b[1] but it is not swapping.
Undefined behavior for
a[0]^=a[1]^=a[0]^=a[1];. Order of evaluation and assignment is not defined.