what *p1 ^= *p2; does in c

后端 未结 4 849
别那么骄傲
别那么骄傲 2021-01-29 06:09

In C what does this statement do?

*p1 ^= *p2;

p1 and p2 are char pointers pointing to two different address of a char

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 06:29

    It should probably be easier to understand if you see it this way instead:

    char c1 = *p1;
    char c2 = *p2;
    
    c1 = c1 ^ c2;
    
    *p1 = c1;
    

    That's basically what the code you show is doing.

    This of course relies on you knowing how exclusive or actually works, and know about pointer dereferencing too.

提交回复
热议问题