0
what is call by reference
logical as well as machine way needed
1 ответ
0
When calling some variable by reference it means that the argument passed to the function is exactly that variable, not a copy of it.
Consider this example:
int a = 5;
void addOne(int num) { // Call by value
num++;
}
addOne(a);
cout << a; // Prints 5.
Why? Because when passing by value the function makes a copy of the argument passed to it and uses that copy to do the operations.
Now, if we change
void addOne(int num) // Call by value
to
void addOne(int& num) // Call by reference
the program outputs 6, because the function doesnt make a copy of it, it uses that same variable with the same memory address.