C++ Program To Swap Value By Passing Reference | C Programming

C++ Program To Swap Value By Passing Reference

#include <iostream>
using namespace std;
#include <iomanip>
int swap(int &a, int &b)
{
    int temp;
    temp = a;
    a = b;
    b = temp;
    return 0;
}
int main()
{
    int a, b;
    cout << "Enter the value of a and b \n";
    cin >> a >> b;
    swap(a, b);
    cout << "The swapped value of a is " << a << endl
         << "The swapped value of b is " << b;
}

OUTPUT

Enter the value of a and b
60
90
The swapped value of a is 90
The swapped value of b is 60

Comments

Popular posts from this blog

C Program for SCAN Disk Scheduling Algorithm | C Programming

C program to Find Cartesian Product of Two Sets | C programming

C Program To Check The String Is Valid Identifier Or Not | C Programming