LearnFrenzy
Sign in Take a free test

Variable Number of Arguments · Exercise 1 of 4

Variable Number of Arguments Variable Arguments MCQ

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twelve multiple-choice questions on variadic functions, stdarg.h macros, promotions, wrappers, variadic macros and C23. Pick an option to check your answer instantly.

Question 1 Easy

Which header defines va_list, va_start, va_arg and va_end?

A <stdarg.h>
B <stdlib.h>
C <varargs.h>
D <stdio.h>
Question page & discussion
Question 2 Easy

Where can ... appear in a function's parameter list?

A Only as the last item
B Anywhere
C Only as the first item
D Only in main()
Question page & discussion
Question 3 Easy

In int f(int a, double b, ...), how should va_start be called (C17)?

A va_start(ap, a)
B va_start(ap, ...)
C va_start(ap, b)
D va_start(ap, 2)
Question page & discussion
Question 4 Easy

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
Question page & discussion
Question 5 Medium

A caller passes a float variable to a variadic function. How must it be read?

A va_arg(ap, float)
B va_arg(ap, double)
C va_arg(ap, int)
D (float) va_arg(ap, float *)
Question page & discussion
Question 6 Medium

How should a char argument be read with va_arg?

A va_arg(ap, char)
B va_arg(ap, char *)
C (char) va_arg(ap, int)
D va_arg(ap, short)
Question page & discussion
Question 7 Easy

How does printf() decide how many arguments to read?

A From the conversion specifications in the format string
B The compiler passes the count
C It reads until it finds 0
D From the stack size
Question page & discussion
Question 8 Medium

Why would a function use va_copy()?

A To traverse the variable arguments more than once, since a va_list can be used only once
B To copy the arguments into an array
C To pass ... to another function
D To end the list
Question page & discussion
Question 9 Medium

Why does the library provide vprintf(), which takes a va_list?

A So variadic wrapper functions can forward their arguments – a ... cannot be passed on to printf
B It is faster than printf
C It prints in verbose mode
D It handles wide characters
Question page & discussion
Question 10 Medium

A function calls va_start but returns without calling va_end. What does the standard say?

A It is fine – va_end does nothing
B It causes a compile error
C The behaviour is undefined: every va_start (and va_copy) must be matched by va_end in the same function
D The arguments leak
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links