Wednesday, August 08, 2012

Swap two values by using pointers as arguments to a function


void swap(int *, int *);
void main(void) {
int a,b;
a=10;
b=20;
swap(&a,&b);
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
}
void swap(int *x, int *y) {
int temp;
temp=*x;
*x=*y;
*y=temp;
}