C Programming Questions and Answers – Variable Length Argument – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Variable Length Argument – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

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

  1.     #include <stdio.h>
  2.     #include <stdarg.h>
  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
View Answer

Answer: c
Explanation: None.
advertisement

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
View Answer

Answer: a
Explanation: None.
Free 30-Day Java Certification Bootcamp is Live. Join Now!

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
View Answer

Answer: a
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: a
Explanation: None.
advertisement

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
View Answer

Answer: b
Explanation: 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
View Answer

Answer: c
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
I’m Manish - Founder and CTO at Sanfoundry. I’ve been working in tech for over 25 years, with deep focus on Linux kernel, SAN technologies, Advanced C, Full Stack and Scalable website designs.

You can connect with me on LinkedIn, watch my Youtube Masterclasses, or join my Telegram tech discussions.

If you’re in your 40s–60s and exploring new directions in your career, I also offer mentoring. Learn more here.