LearnFrenzy
Sign in Take a free test

Pointers · Pointer Basics MCQ · Question 12

How is call by reference done in C? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links