LearnFrenzy
Sign in Take a free test

Variable Number of Arguments · Variable Arguments MCQ · Question 4

How does a variadic function know the argument count? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

How does a variadic function find out how many arguments were passed?

  • A From va_count(ap)
  • B va_arg returns NULL at the end
  • C sizeof(...)
  • D It cannot by itself – the caller must say, via a count, a sentinel value or a format string Correct
Correct Answer: Option D

Nothing marks the end of the arguments. Reading past them is undefined behaviour, so the function relies on a convention.

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