Written by **Sagar Rabidas**January 28, 2022

8 min read

C++

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

- The XOR operator is one of the bitwise operators in C++, which takes two operators as the operands, and on each bit of the two operands, the XOR operation is performed.
- The result of the XOR operation on the given two bits of the two operands is zero if the two bits of the given two operands are zero.
- The result of the XOR operation on the given two bits of the two operands is zero if the two bits of the given two operands are one.
- The result of XOR operation on the given two bits of the two operands is one if one of the two bits of the given two operands is zero or one and the other bit is one or zero, that is, if the two bits of the given two operands are different, the result is one.

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;

}

C

C++

C++ XOR operator

Was this blog helpful?

Trending Technologies

15

Software40

DevOps46

Frontend Development24

Backend Development20

Server Administration17

Linux Administration26

Data Center24

Sentry24

Terraform23

Ansible83

Docker70

Penetration Testing16

Kubernetes21

NGINX20

JenkinsX17

Recommended Blogs

8

Recommended Threads

8

Anik Adhikary

Anik Adhikary

Anik Adhikary