call by value and call by reference in c code example
Example 1: call by address call by reference which is more efficient
The fact that only the addresses and not the data values are passed during a function call, the call-by-reference method is also more efficient, especially when the function arguments involve complex data types. However the call-by-reference method is also more prone to errors if it is not used carefully.
Example 2: call by reference
//Call By Reference
#include<stdio.h>
void function(int *, int *); //function declaration
int main()
{
int a,b;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
function(&a,&b); //passing the address of both the variables( CALL BY REFERENCE)
}
void function(int *p,int *q) //function defination
{
printf("printing variables from function a=%d b=%d",*p,*q);
}
//code by Dungriyal..