Call by value
Program:
//CALL BY REFERENCE
#include<stdio.h>
void Call_value(int *a){
printf("By calling Value of the a from Main Function using Pointer.\n");
printf("OR by Address of the original varialble. \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:46
By calling Value of the a from Main Function using Pointer.
OR by Address of the original varialble.
--->>> a=46
Swap two numbers using Call by Reference
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;
temp=*a;
*a=*b;
*b=temp;
printf("\n-> After Swapping:\n\ta=%d\n\tb=%d\n",*a,*b);
}
#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;
temp=*a;
*a=*b;
*b=temp;
printf("\n-> After Swapping:\n\ta=%d\n\tb=%d\n",*a,*b);
}
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;
temp=*a;
*a=*b;
*b=temp;
printf("\n-> After Swapping:\n\ta=%d\n\tb=%d\n",*a,*b);
}
Expected O/P:
Enter the Two Number:
46
34
->Before Swapping:
a=46
b=34
-> After Swapping:
a=34
b=46
Enter the Two Number:
46
34
->Before Swapping:
a=46
b=34
-> After Swapping:
a=34
b=46
46
34
->Before Swapping:
a=46
b=34
-> After Swapping:
a=34
b=46
0 Comments
Post a Comment