The correct answer is: A. Reference
A reference is a variable that stores the address of another variable. When a function receives a reference to a variable, it can modify the value of the variable in the calling function.
A value is a copy of the data stored in a variable. When a function receives a value, it cannot modify the value of the variable in the calling function.
An address is the location of a variable in memory. When a function receives an address, it can access the variable in the calling function.
A pointer is a variable that stores the address of another variable. Pointers are often used to pass data to functions.
Here is an example of how a function can receive information by value:
“`c
void change_value(int x) {
x = 10;
}
int main() {
int a = 5;
change_value(a);
printf(“%d\n”, a); // prints 5
}
“`
In this example, the function change_value
receives the value of the variable a
. The function then changes the value of a
to 10. However, the change is not reflected in the calling function, because the function only received a copy of the value of a
.
Here is an example of how a function can receive information by reference:
“`c
void change_reference(int x) {
x = 10;
}
int main() {
int a = 5;
change_reference(&a);
printf(“%d\n”, a); // prints 10
}
“`
In this example, the function change_reference
receives a reference to the variable a
. The function then changes the value of a
to 10. This change is reflected in the calling function, because the function received a reference to a
.