Question 12
Back to Exercise
How does a C function change a variable that belongs to its caller?
- A By declaring the variable global inside the function
- B By returning the variable with the & operator
- C C cannot do this
- D By receiving the variable's address and writing through the pointer Correct
Correct Answer: Option D
C passes arguments by value, so the function gets a copy. Passing &x gives it the address; then *ptr = … changes the caller's x. That is how scanf() and swap(&a, &b) work.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!