what is call by value and call by reference code example
Example 1: , Call by Reference,
void swap(int *x, int *y) {
int temp;
temp = *x;
*x = *y;
*y = temp;
return;
}
Example 2: call by reference
#include<stdio.h>
void function(int *, int *);
int main()
{
int a,b;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
function(&a,&b);
}
void function(int *p,int *q)
{
printf("printing variables from function a=%d b=%d",*p,*q);
}
Example 3: what is call by value and call by reference
void swap(int *x, int *y) {
int temp;
temp = *x;
*x = *y;
*y = temp;
return;
}