Search here

Pages

Showing posts with label Parameter Passing. Show all posts
Showing posts with label Parameter Passing. Show all posts

Saturday, August 13, 2011

Pass by Value(swapping)

Program for Passby Value-PARAMETER PASSING 
#include<iostream.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a,b;
cout<<"Enter any two numbers";
cin>>a>>b;
swap(a,b);
cout<<"\n the swapped valuesin the main funtion are"<<a<<"and"<<b;
getche();
}
void swap(int x,int y)
{
int t;
t=x;
x=y;
y=t;
cout<<"\n the  swapped values in the function are"<<x<<"and"<<y;

}
Read Full

Pass by Address(swapping)

Program for Passby Address-PARAMETER PASSING 
#include<iostream.h>
#include<conio.h>
void swap(int &,int &);
void main()
{
int a,b;
cout<<"Enter any two numbers";
cin>>a>>b;
swap(a,b);
cout<<"\n the swapped valuesin the main funtion are"<<a<<"and"<<b;
getche();
}
void swap(int &x,int &y)
{
int t;
t=x;
x=y;
y=t;
cout<<"\n the  swapped values in the function are"<<x<<"and"<<y;

}
Read Full

Pass by reference(swapping)

 Program for Passby reference-PARAMETER PASSING
#include<iostream.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
int a,b;
cout<<"Enter any two numbers";
cin>>a>>b;
swap(&a,&b);
cout<<"\n the swapped valuesin the main funtion are"<<a<<"and"<<b;
getche();
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
cout<<"\n the  swapped values in the function are"<<  *x<<"and"<<     *y;

}

Read Full