In C programming, call by reference is a method of passing arguments to a function where the function receives the memory address of the variables passed as arguments, rather than their values. This means that any changes made to the variables within the function affect the original variables.
The basic syntax for passing arguments by reference in C is as follows:
Syntax :
return_type function_name ( type *variable_name )
{
// body of Statement ;
}
Here, the return_type specifies the data type of the value that the function will return, the function_name is the name of the function, and the variable_name is the name of the variable being passed to the function. The * before the variable name indicates that the argument is being passed by reference. Here is an example of a function that swaps the values of two integers passed by reference:
//Call by Reference Function in C Programming #include<stdio.h> void swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp; } int main() { int a,b; printf("\nEnter The Value of A & B : "); scanf("%d%d",&a,&b); printf("\nBefore Swap A : %d | B : %d",a,b); swap(&a,&b); printf("\nAfter Swap A : %d | B : %d",a,b); return 0; }To download raw file Click Here
Enter The Value of A & B : 10 20 Before Swap A : 10 | B : 20 After Swap A : 20 | B : 10
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions