My simple approach to explain the difference between pass by value and pass by reference irrespective of any programming language.
Consider the below code
int i = 5; process(i); // pass by reference process(5); // pass by value SOP(i); public void process(int a){ // do something }
In the above code if you are passing i as an argument to the method then it is pass by reference and if you are passing 5 then it is pass by value.
If you pass i (pass by reference) then the change in the data in the function will affect the data in caller.
But if you pass 5 (pass by value) then the change in the data in the function will not affect the data in caller.
I hope i am making a very clear point and am not violating any object credentials.
No comments:
Post a Comment