In this we pass copy of actual variables in function as a parameter. Hence any modification on parameters inside the function will not reflect in the actual variable.
example:
#include<stdio.h>
int main(){
int a=5,b=10;
swap(a,b);
printf("%d%d",a,b);
return 0;
}
void swap(int a,int b){
int temp;
temp =a;
a=b;
b=temp;
}
Pass by reference :
In this we pass memory address by a reference its actual variables in function as a parameter. Hence, any modification on parameters inside the function will reflect in the actual variable.
#incude<stdio.h>
int main(){
int a=5,b=10;
swap(&a,&b);
printf("%d %d",a,b);
return 0;
}
void swap(int *a,int *b){
int *temp;
*temp =*a;
*a=*b;
*b=*temp;
}
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Pass by value :
In this we pass copy of actual variables in function as a parameter. Hence any modification on parameters inside the function will not reflect in the actual variable.
example:
#include<stdio.h> int main(){ int a=5,b=10; swap(a,b); printf("%d%d",a,b); return 0; } void swap(int a,int b){ int temp; temp =a; a=b; b=temp; }Pass by reference :
In this we pass memory address by a reference its actual variables in function as a parameter. Hence, any modification on parameters inside the function will reflect in the actual variable.
#incude<stdio.h> int main(){ int a=5,b=10; swap(&a,&b); printf("%d %d",a,b); return 0; } void swap(int *a,int *b){ int *temp; *temp =*a; *a=*b; *b=*temp; }