What does "^=" in c++ mean? [duplicate]

^ symbol stands for Bitwise Xor in C++, and in most programming languages. Refer Sample Code & Truth Table for better explanation. Also a^=b is short hand for a = a^b.

Sample Code

#include <iostream>
using namespace std;

int main() {
    int a = 5, b = 9; // a = 5(00000101), b = 9(00001001)
    cout<<int(a^b); // The result is 12(00001100)
    return 0;
}

Live Code

Truth Table

enter image description here

Leave a Comment