pass by reference in c,call by reference in c program,pass by reference in c example
Write a c program to demonstrate the pass by reference mechanism
#include<stdio.h>
#include<conio.h>
void main()
{
void swap(int *,int *);
int a,b;
clrscr();
printf("Enter two numbers:\n");
scanf("%d%d",&a,&b);
printf("Before calling the function a=%d and
b=%d\n",a,b);
swap(&a,&b);
printf("After calling the function a=%d and
b=%d",a,b);
getch();
}
void swap(int *x, int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
}
Output:
Enter two numbers:
2
4
Before calling the function a=2 and b=4
No comments: