Write a c program to swap two numbers using call by reference
#include<stdio.h>
#include<conio.h>
void main()
{
void swap(int *, int *);
int a=10,b=20;
printf(“Entered numbers are a=%d and b=%d\n”,a,b);
swap(&a,&b);
printf(“Entered numbers after swapping are a=%d and
b=%d”,a,b);
getch();
}
void swap(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Output:
Entered numbers are a=10 and b=20
No comments: