What is Call By Value in C
In call by value method, the called function creates its own copies of the original values that are sent to it. The changes made in the value are made on the copy of the called function and do not affect the main function.
Example of call by value in c
int main ()
{
int a=6 ;
cout<< "a =" << a ;
change (a) ;
cout <<"\n a=" << a ;
return 0;
}
void change (int b)
{
b = 10 ;
}
What is Call By Reference in C
In call by reference method, the called function works with the original value using their reference. The changes made are reflected back on the original code.
Example of call by value in c
int main ()
{
int a=5 ;
cout<< "a =" << a ;
change (a) ;
cout <<"\n a=" << a ;
return 0;
}
void change (int & b)
{
b = 10 ;
}