Of the three ways to pass arguments to functions, only passing by _____ and passing by _____ allow the function to modify the argument in the calling program A. reference, pointer B. array, location C. array, pointer D. None of the above

[amp_mcq option1=”reference, pointer” option2=”array, location” option3=”array, pointer” option4=”None of the above” correct=”option1″]

The correct answer is: A. reference, pointer.

When a function is called, the arguments are passed to the function in a way that depends on the type of the argument. For value types, the argument is copied to the function’s stack frame. For reference types, the reference to the argument is passed to the function. For pointer types, the pointer to the argument is passed to the function.

The function can modify the argument in the calling program only if the argument is passed by reference or by pointer. If the argument is passed by value, the function cannot modify the argument in the calling program.

Here is an example of passing an argument by value:

“`c++
void foo(int x) {
x = 10; // This changes the value of x in the function, but not in the calling program.
}

int main() {
int x = 5;
foo(x);
// x is still 5 in main().
}
“`

Here is an example of passing an argument by reference:

“`c++
void foo(int& x) {
x = 10; // This changes the value of x in the calling program.
}

int main() {
int x = 5;
foo(x);
// x is now 10 in main().
}
“`

Here is an example of passing an argument by pointer:

“`c++
void foo(int x) {
x = 10; // This changes the value of the object pointed to by x in the calling program.
}

int main() {
int x = 5;
foo(&x);
// x is now 10 in main().
}
“`