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;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|