Call by value

Program:

//CALL BY VALUE

#include<stdio.h>
void Call_value(int a){
printf("By calling Value of the a from Main Function.\n");
printf("\n\t--->>> a=%d\n",a);
}
int main(){
int n ;
printf("Enter the Number:");
scanf("%d",&n);
Call_value(n);
return 0;
}

Expected O/P:



Enter the Number:456
By calling Value of the a from Main Function.

--->>> a=456

Swap two numbers using Call by value

Program:

#include<stdio.h>
void swap(int,int);
int main(){
int n1,n2;
printf("Enter the Two Number:\n");
scanf("%d%d",&n1,&n2);
printf("->Before Swapping:\n\ta=%d\n\tb=%d",n1,n2);
swap(n1,n2);
return 0;
}
void swap(int a,int b){
int temp;
a=b;
temp=b;
b=temp;
printf("\n-> After Swapping:\n\ta=%d\n\tb=%d\n",a,b);
}

Expected O/P:



Enter the Two Number:
48
91
->Before Swapping:
a=48
b=91
-> After Swapping:
a=91
b=91