+ 1
What is the difference between call by reference and call by variable in Java? If possible, implement one example.
6 Answers
+ 1
Call by value :
It means you are passing arguments by its value means you are passing arguments copy to parameter.
Now if parameter value is changed inside function it will not change actual arguments value.
Example (C language):
int increment (int a) //parameter
{
a+1;
}
int main()
{
int x=5;
increment (x); //argument
......... /* here there will be no change to value of x even it is change in function i.e incremented*/
}
Hope this helpsâşď¸âşď¸.
+ 1
Call by reference :
It means you are passing arguments by its reference means you are passing arguments reference to parameter.
Now if parameter value is changed inside function it will change actual arguments value.
Example (C language):
int increment (int *a) //parameter
{
*a + 1;
}
int main()
{
int x=5;
increment (&x); //argument
......... /* here value of x will be changed if it is changed in function i.e incremented*/
}
Hope this helpsâşď¸âşď¸.
+ 1
wow thank you
+ 1
Patricia Yu Hee Kim and Emmanuel Kwesi Amankrah Most welcome.
Happy this explanation help youâşď¸âşď¸.
0
Thank you very much.
0
yeah it did