C program to implement "Call By Refrence"

C program for "Call By Reference"

The address of memory location A and B are passed to the function swap and the pointers *x and *y accept those values.
So, now the pointer x and y points to the address of A and B respectively.
When, the value of pointers are changed, the value in the pointed memory location also changes correspondingly.
Hence, changes made to *x and *y are reflected in A and B in the main function.
This technique is known as Call by Reference in C programming.


#include <stdio.h> 
#include <conio.h>
void swapref(int*,int*); //Declaration of the swap value by refrence function
void main()
{
 int a,b; //Initialization of variable
 clrscr();
 printf("\n\nSwaping value using Call By Reference\n");
 //Fetch values of A & B from the user
 printf("Enter the first value A: ");
 scanf("%d",&a);
 printf("Enter the second value B: ");
 scanf("%d",&b);
 printf("\nValue inside the main function:\n");
 printf("A= %d B= %d",a,b);
 //Calling the refrence function
 swapref(&a,&b);
 getch();
}
void swapref(int *x,int *y)
{
 int temp; //Declare temp variable to store data temporary 
 //Swapping the values 
 temp=*x;
 *x=*y;
 *y=temp;
 printf("\nValue inside swap function:\n");
 printf("A= %d B= %d",*x,*y); //Getting the output on the screen
}

call by reference,call by value,call by refrence,reference,call by refrence in c,function call by reference in c ++,function call by reference in c ++ hindi,c programming video tutorials by lsoit.in,pass by reference,call by refrence in c++,call by refrence in hindi,call by value in scala,call by name in scala,call by reference swap program in c++ (hindi)





Happy Coding :)

Comments

Popular posts from this blog

MultiSelection of Item in Recycler View

Upload Image From Android To Php Server

Merge Sort