#include<iOStream>
template<typename _Ty>void swap (_Ty& a, _Ty& b)
{
_Ty temp = a;
a = b;
b = temp;
}
int main()
{
int x = 42;
int y = 0;
std::cout << "Before swap:" << std::endl;
std::cout << "x = " << x << ", y = " << y << std::endl;
swap (x, y);
std::cout << "After swap:" << std::endl;
std::cout << "x = " << x << ", y = " << y << std::endl;
}
Example Output
Before swap:
x = 42, y = 0
After swap:
x = 0, y = 42
Copyright © 2026 eLLeNow.com All Rights Reserved.