+ 6
what is difference between pass by value and pass by reference
4 ответов
+ 6
When you pass by value the function cannot change the argument, and when passing by reference can.
+ 3
PASS BY VALUE:
When a value is passed, the value is sent to the formal argument.
Any change made in the formal argument is not made in the actual argument.
PASS BY REFERENCE:
When a value is passed, the address of the value is referenced to the formal argument.
Any change made in the formal argument is referred to the actual argument.
+ 2
in pass by value, we pass the arguments actual value through the variable name and in pass by reference, we pass the address of the variable.
0
in pass by value we pass value of the actual argument to the formal argument and
in pass by reference we pass the address of actual argument
so when we make changes to the formal arguments they doesn't affect actual argument because a copy of actual arguments is send to the formal arguments
in call by reference we send addresses so changes made to the formal arguments affects the actual arguments
you can check by swapping program