C++ Swap By Pointer

#include<iostream>
using namespace std;
void anik(double *p, double *q)
{
    double t;

    t = *p;
    *p = *q;
    *q = t;

}
int main()
{
    double a, b;

    cout << "Enter a : ";
    cin >> a ;
    cout << "\nEnter b : ";
    cin >> b;
    cout << endl;

    anik(&a, &b);

    cout << "\n\nAfter Swapping a :: " << a << endl;
    cout << "\nAfter Swapping b :: " << b << endl;

    return 0;
}

Comments