Difficulty: Easy
Correct Answer: False
Explanation:
Introduction / Context:
This conceptual question clarifies what va_start
actually does in the C varargs mechanism. Misunderstandings about whether it references fixed (named) arguments or variable (unnamed) arguments can lead to incorrect code and undefined behavior.
Given Data / Assumptions:
void f(int count, ...);
va_start(ap, count)
is used to begin traversal.
Concept / Approach:va_start
initializes a va_list
object to allow access to the unnamed (variable) arguments that appear after the last fixed parameter. Its second argument must be exactly the last named parameter in the function’s parameter list. It does not “point to the fixed arguments”; it uses the location of the last fixed argument as an anchor to locate the first variable argument.
Step-by-Step Solution:
Define va_list ap;
Call va_start(ap, count);
→ positions ap
to retrieve the first variable argument with va_arg
.Retrieve each successive unnamed argument → va_arg(ap, type)
repeatedly.End with va_end(ap);
Verification / Alternative check:
Reading the standard or any reputable C reference confirms va_start
enables access to the variable argument list, not the fixed ones.
Why Other Options Are Wrong:
True reverses the direction of the relationship: fixed argument merely identifies the boundary; iteration is over the variable list. Other distractors are irrelevant (C++ has its own facilities, but the question is about C).
Common Pitfalls:
Mis-anchoring va_start
to the wrong parameter and assuming it provides access to named parameters, which it does not.
Final Answer:
False
Discussion & Comments