Uploaded by Esther Ng

C++ Integer Swapping Code Snippet

advertisement
#include <iostream>
void SwapNumbers(int& i_numA, int& i_numB)
{
const int copy = i_numB;
i_numB = i_numA;
i_numA = copy;
}
int main_Swap2Integers()
{
int numA = 1, numB = 2;
std::cout << "Before Swapping:" << std::endl;
std::cout << "Number A: " << numA << std::endl;
std::cout << "Number B: " << numB << std::endl;
SwapNumbers(numA, numB);
std::cout << "\nAfter Swapping:" << std::endl;
std::cout << "Number A: " << numA << std::endl;
std::cout << "Number B: " << numB << std::endl;
return 0;
}
Download