Swapping integers. - C++ Data Type

C++ examples for Data Type:int

Description

Swapping integers.

Demo Code

#include <iostream>

int main()/*from   w  w  w . jav a  2s . com*/
{
  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;
}

Result


Related Tutorials