Program to illustrates passing by reference


    #include<iostream.h>
    #include<conio.h>
    void swap (int&, int&) ;
    void main( )
    {
        int a = 11, b = 22;
        cout <<"\n Before swap a = "<<a<<" and b = "<<b;
        swap(a, b);
        cout <<"\n After swap a = "<<a<<"and b = "<<b;
    }
    void swap(int& x, int& y)
    {   
           //exchange the values of x and y
        int temp = x;
        x = y;
        y = temp;
    }

No comments:

Post a Comment