250+ TOP MCQs on Variable Length Argument and Answers

C programming questions on “Variable Length Argument”. One shall practice these questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C programming questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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

1. What will be the output of the following C code?

  1.     #include 
  2.     #include 
  3.     void func(int, ...);
  4.     int main()
  5.     {
  6.         func(2, 3, 5, 7, 11, 13);
  7.         return 0;
  8.     }
  9.     void func(int n, ...)
  10.     {
  11.         int number, i = 0;
  12.         va_list start;
  13.         va_start(start, n);
  14.         while (i != 3)
  15.         {
  16.             number = va_arg(start, int);
  17.             i++;
  18.         }
  19.         printf("%d", number);
  20.     }

a) 3
b) 5
c) 7
d) 11
Answer: c
Clarification: None.

2. Which of the following function with ellipsis are illegal?
a) void func(…);
b) void func(int, …);
c) void func(int, int, …);
d) none of the mentioned
Answer: a
Clarification: None.

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
Answer: a
Clarification: None.

4. Which header file includes a function for variable number of arguments?
a) stdlib.h
b) stdarg.h
c) ctype.h
d) both stdlib.h and stdarg.h
Answer: b
Clarification: None.

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
Answer: b
Clarification: None.

6. The type va_list in an argument list is used ________
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
Answer: a
Clarification: None.

7. In a variable length argument function, the declaration “…” can _______
a) Appear anywhere in the function declaration
b) Only appear at the end of an argument list
c) Nothing
d) None of the mentioned
Answer: b
Clarification: None.

8. Each call of va_arg _______
a) Returns one argument
b) Steps va_list variable to the next
c) Returns one argument & Steps va_list variable to the next
d) None of the mentioned
Answer: c
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *