xxxxxxxxxx
#include <iostream>
using namespace std;
int main()
{
int a,b,temp;
cout <<"Enter two values that you wants to swap:";
cin >> a >> b;
cout << "Before swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping." << endl;
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
xxxxxxxxxx
#include <bits/stdc++.h>
// OR
#include <algorithm> // if on C++98
#include <utility> // if on C++11
int a = 2, b = 5;
swap(a, b);
vector<int> v = { 7, 5, 16, 8 }; // #include <vector>
swap(v[0], v[2]);