The correct answer is C. Pass by reference.
Passing a variable’s address is referred to as pass by reference. In pass by reference, the address of the variable is passed to the function, and the function can modify the value of the variable in the calling function.
Pass by value is a method of passing arguments to a function in which a copy of the argument’s value is passed to the function. The function can then modify the copy of the value, but the original value in the calling function is not affected.
Pass by pointer is a method of passing arguments to a function in which the address of the argument is passed to the function. The function can then modify the value of the argument through the pointer.
Here is an example of pass by reference in C++:
“`c++
void change_value(int &x) {
x = 10;
}
int main() {
int a = 5;
change_value(a);
cout << a << endl; // prints 10
}
“`
In this example, the variable a is passed by reference to the function change_value(). The function then modifies the value of a to 10. When the function returns, the value of a in the calling function is also 10.
Here is an example of pass by value in C++:
“`c++
void change_value(int x) {
x = 10;
}
int main() {
Join Our Telegram Channel