Saturday 1 November 2014
22. Write a program to swap the two values using pointers and UDF.
22. Write a program to swap the two values using pointers and UDF.
PRO-22:
#include<stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{ int
x,y,*pa,*pb;
clrscr();
pa=&x;
pb=&y;
x=10;
y=20;
printf("\nBefore
Swap :: X =%d Y =
%d",x,y);
swap(pa,pb);
printf("\n\nAfter Swap :: X
=%d Y = %d",
x,y);
getch();
}
void swap(int *u,int *v)
{ int
temp;
temp=*u;
*u=*v;
*v=temp;
}
OUTPUT:
Before Swap
:: X =10
Y = 20
After Swap :: X
=20 Y = 10
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment