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!