C MCQs: Variable Length Arguments- Part 1

Here is a listing of C programming questions on “Variable Length Argument” along with answers, explanations and/or solutions:

1. What is the output of this C code?

#include <stdio.h>
 #include <stdarg.h>
 void func(int, ...);
 int main()
 func(2, 3, 5, 7, 11, 13);
 return 0;
 void func(int n, ...)
 int number, i = 0;
 va_list start;
 va_start(start, n);
 while (i != 3)
 number = va_arg(start, int);
 printf("%d", number);

a) 3
b) 5
c) 7
d) 11

2. Which of the following function with ellipsis are illegal?

a) void func(…);
b) void func(int, …);
c) void func(int, int, …);
d) Both (a) and (c)

3. Which of the following data-types are promoted when used as a parameter for an ellipsis?

a) char
b) short
c) int
d) None of the mentioned

4. Which header file includes a function for variable number of arguments?

a) stdlib.h
b) stdarg.h
c) ctype.h
d) Both (a) and (b)

5. Which of the following macro extracts an argument from the variable argument list (ie ellipsis)      and advance the pointer to the next argument?

a) va_list
b) va_arg
c) va_end
d) va_start

6. The type va_list is used in an argument list

a) To declare a variable that will refer to each argument in turn;
b) For cleanup
c) To create a list
d) There is no such type

7. The declaration … can

a) Appear anywhere in the function declaration
b) Only appear at the end of an argument list.
c) Nothing
d) Both a & b

8. Each call of va_arg

a) returns one argument
b) Steps va_list variable to the next
c) Both a & b
d) None of the mentioned

 Next –> C MCQs: Variable Length Arguments- Part 2

Leave a Reply