C++ Bitwise Operator Swapping integers

Description

C++ Bitwise Operator Swapping integers

#include <iostream>

int main()//from w ww  .j  a  v  a  2s  .  c  o  m
{
  int first {}, second {};
  std::cout << "Enter two integers separated by a space: ";
  std::cin >> first >> second;

  first ^= second;
  second ^= first;
  first ^= second;
  std::cout << "In reverse order they are " << first << " and " << second << std::endl;
}



PreviousNext

Related