Software Developer
The xor operator is one of the bitwise operators in c++, which takes two operators as the operands and on every little bit of the two operands. The xor operation is performed, and the result of the xor operation at the given two bits of the 2 operands is 0. If the 2 bits of the given two operands is 0 and the result of xor operation on the given two bits of the two operands is 0 if the 2 bits of the given two operands is one and the result of xor operation on the given two bits of the 2 operands is one if one of the two bits of the given two operands is 0 or one and the alternative bit is one or 0, this is if the 2 bits of the given two operands are exclusive, the result is one.
variable1 ^ variable2
Different examples are mentioned below:
C++ program to demonstrate the XOR operator in C++ to perform XOR operation on the given two operands and display the result:
//The header iostream is included to be able to make use of cin and cout statements
#include <iostream>
using namespace std;
//main method is called
int main()
{
//an integer variable called a is defined to store the first integer value
int a = 5;
//an integer variable called b is defined to store the second integer value
int b = 4;
//an integer variable called c is defined to store the result of XOR operation on the two values stored in the variables a and b
int c = a ^ b;
cout << "The result after performing XOR operation on a and b is " << c;
return 0;
}
C++ program to demonstrate the XOR operator in C++ to perform XOR operation on the given two operands and display the result:
//The header iostream is included to be able to make use of cin and cout statements
#include <iostream>
using namespace std;
//main method is called
int main()
{
//an integer variable called a is defined to store the first integer value
int a = 20;
//an integer variable called b is defined to store the second integer value
int b = 35;
//an integer variable called c is defined to store the result of XOR operation on the two values stored in the variables a and b
int c = a ^ b;
cout << "The result after performing XOR operation on a and b is " << c;
return 0;
}
C++ program to demonstrate the XOR operator in C++ to perform XOR operation on the given two operands and display the result:
//The header iostream is included to be able to make use of cin and cout statements
#include <iostream>
using namespace std;
//main method is called
int main()
{
//an integer variable called a is defined to store the first integer value
int a = 100;
//an integer variable called b is defined to store the second integer value
int b = 35;
//an integer variable called c is defined to store the result of XOR operation on the two values stored in the variables a and b
int c = a ^ b;
cout << "The result after performing XOR operation on a and b is " << c;
return 0;
}