0% found this document useful (0 votes)
54 views

Write A Program of Call by Reference

This C program demonstrates call by reference by passing the addresses of two variables into a swap function. The user inputs two numbers which are printed before being passed to the swap function. The swap function receives the addresses of the variables, swaps their values by assigning one to a temporary variable and then assigning the other variable's value. This swaps the values of the original variables as shown by the output printing after the swap.

Uploaded by

Shawn Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Write A Program of Call by Reference

This C program demonstrates call by reference by passing the addresses of two variables into a swap function. The user inputs two numbers which are printed before being passed to the swap function. The swap function receives the addresses of the variables, swaps their values by assigning one to a temporary variable and then assigning the other variable's value. This swaps the values of the original variables as shown by the output printing after the swap.

Uploaded by

Shawn Rodriguez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*write a program of call by reference*/

#include<stdio.h>
#include<conio.h>
void main()
{
void swap(int*a,int*b);
int a,b;
printf(enter any two numbers);
scanf(%d%d,&a,&b);
printf(before swapping a=%d,b=%d,a,b);
swap(&a,&b);
printf(after swapping a =%d, b=%d,a,b);
getch();
}
void swap(int*x,int*y)
{
int z;
z=*x;
*x=*y;
*y=*z;
}

OUTPUT
enter any two numbers 6 7
before swapping a=6 b=7
after swapping a=7 b=6

You might also like