C++ program to swap two numbers using built in swap function from c++ standard library


Levels of difficulty: / perform operation:

What is swapping?
It means exchange things with each other
For more information have a look at swapping concept by Wikipedia

Calling Methods:
swap();
std:swap();

C++ code which take two numbers from user and swap using built in swap function. Program takes two input from user and displays numbers before and after swapping



C++ Program

#include <iostream>
using namespace std;
void swap() {
	cout<<"this is my swap";
}
int main() {
	int firstNum , secondNum;
	cout<<"Enter value for First Number:   ";
	cin>>firstNum;
	cout<<"Enter value for Second Number:  ";
	cin>>secondNum;
	cout<<"\n\n";
	cout<<"Values BEFORE Calling Built in Swap Function"<<endl<<endl;
	cout<<"\tFirst  Number = "<<firstNum<<endl;
	cout<<"\tSecond Number = "<<secondNum<<endl;
	cout<<"\n\n";
	std::swap( firstNum , secondNum );
	cout<<"Values AFTER Calling Bulit in  Swap Function"<<endl<<endl;
	cout<<"\tFirst Number = "<<firstNum<<endl;
	cout<<"\tSecond Number = "<<secondNum<<endl;
	return 0;
}