InterviewSolution
| 1. |
Difference Between Pass By Reference And Pass By Value? |
|
Answer» Pass By Reference: In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect to the ACTUAL parameters
Pass By VALUE:
In case of pass by value, the change in the sub-function will not cause any change in the main function whereas in pass by reference the change in the sub-function will change the value in the main function. Pass by value sends a COPY of the data stored in the variable you specify, pass by reference sends a direct link to the variable itself. So if you pass a variable by reference and then change the variable inside the block you passed it into, the original variable will be changed. If you simply pass by value, the original variable will not be able to be changed by the block you passed it into but you will get a copy of whatever it CONTAINED at the time of the call. Pass By Reference: In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect to the actual parameters Pass By Value: In case of pass by value, the change in the sub-function will not cause any change in the main function whereas in pass by reference the change in the sub-function will change the value in the main function. Pass by value sends a COPY of the data stored in the variable you specify, pass by reference sends a direct link to the variable itself. So if you pass a variable by reference and then change the variable inside the block you passed it into, the original variable will be changed. If you simply pass by value, the original variable will not be able to be changed by the block you passed it into but you will get a copy of whatever it contained at the time of the call. |
|