Tuesday, 9 June 2015

Program to illustrate the use of call-by-refrence method using pointers



Code for Program to illustrate the use of call-by-refrence method using pointers in C++ Programming



 



 



 
#include<iostream.h>
 #include<conio.h>

 void swap(int *,int *);


 main()
    {
       clrscr();


       int value_1;
       int value_2;

       cout<<"\n Enter the value_1 =  ";
       cin>>value_1;

       cout<<"\n Enter the value_2 =  ";
       cin>>value_2;

       cout<<"\n *********  Before Swap()  ********"<<endl;

       cout<<"\n\t Value_1 =  "<<value_1<<endl;
       cout<<"\t Value_2 =  "<<value_2<<endl;

       cout<<"\n *********  After Swap()  ********"<<endl;

       swap(&value_1,&value_2);

       cout<<"\n\t Value_1 =  "<<value_1<<endl;
       cout<<"\t Value_2 =  "<<value_2<<endl;


       getch();
       return 0;
    }


 /*************************************************************************///-------------------------  swap(int *,int *)  -------------------------///*************************************************************************/void swap(int *x,int *y)
    {
       int temp;

       temp=*x;
       *x=*y;
       *y=temp;
    }

No comments:

Post a Comment