C-Variable Numbers and Arguments Questions and Answers
Practice ModeShowing 10 of 28 questions
Q11
In variable argument functions, how does the function know how many arguments were passed?
Answer: Option B
Explanation: The function must have a mechanism (like a count parameter or sentinel value) to determine the number of arguments.
Q12
Which standard library function commonly uses variable arguments?
Answer: Option C
Explanation: printf is the most common example of a variable argument function in C standard library.
Q13
What happens if you call va_arg with the wrong type?
Answer: Option C
Explanation: Using incorrect types with va_arg leads to undefined behavior and potential program crashes.
Q14
Can variable argument functions have no fixed parameters?
Answer: Option B
Explanation: Variable argument functions must have at least one fixed parameter before the ellipsis.
Q15
What is the correct order of using va macros?
Answer: Option A
Explanation: The correct sequence is va_start → va_arg (multiple times) → va_end.
Q16
Which data type promotions occur in variable arguments?
Answer: Option B
Explanation: In variable arguments, char and short are promoted to int, float to double.
Q17
What is a common use case for variable arguments?
Answer: Option C
Explanation: Variable arguments are commonly used for formatted I/O functions and functions that need flexibility in argument count.
Q18
Can you pass structures as variable arguments?
Answer: Option C
Explanation: Structures can be passed but require careful handling due to type promotion rules and size considerations.
Q19
What is the type of the va_list in most implementations?
Answer: Option D
Explanation: va_list is typically implemented as a pointer type that traverses the argument list.
Q20
How can you determine the type of each variable argument?
Answer: Option B
Explanation: The function must know the expected types, typically through format strings or explicit parameters.