NVIDIA Interview Question

Difference between call by value and call by reference

Interview Answer

Anonymous

Sep 24, 2018

In call by value, a copy of actual arguments is passed to respective formal arguments. While, in call by reference, the address of actual arguments is passed to formal arguments, hence any change made to formal arguments will also reflect in actual arguments. If data is passed by value, the data is copied from the variable used in for example main() to a variable used by the function. So if the data passed (that is stored in the function variable) is modified inside the function, the value is only changed in the variable used inside the function.