C Questions and Answers – Variable Argument Lists

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

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

1. How many macros are defined in the header file stdarg.h?
a) one
b) two
c) three
d) four
View Answer

Answer: c
Explanation: The header file stdarg.h has three macros defined in it.

2. The header file stdarg.h defines a variable type ________
a) va_list
b) v_list
c) size_t
d) var_list
View Answer

Answer: a
Explanation: The variable type declared under the header file stdarg.h is va_list. This holds information required by three macros.
advertisement
advertisement

3. The three macros defined by stdarg.h is _________
a) start(), arg() and end()
b) var_start(), var_arg() and var_end()
c) va_start(), va_arg() and va_end()
d) v_start(), v_arg() and v_end()
View Answer

Answer: c
Explanation: The header file stdarg.h has three macros defined in it. They are va_start(), va_arg() and va_end(). va_list is a variable type that holds information needed by the three macros.

4. If access to the varying arguments is desired then the called function shall declare ________ having type va_list.
a) class
b) object
c) function
d) variable
View Answer

Answer: b
Explanation: An object of type va_list has to be created in order to access the varying arguments.
Note: Join free Sanfoundry classes at Telegram or Youtube

5. Which macro retrieves the next argument in the parameter list of the function with type type?
a) type va_arg(va_list ap, type)
b) type var_arg(va_list ap, type)
c) type v_arg(va_list ap, type)
d) type val_arg(va_list ap, type)
View Answer

Answer: a
Explanation: type va_arg(va_list ap,type)
This macro is used to retrieve the next argument in the parameter list of the function with type type.

6. The _______ macro shall be invoked before any access to the unnamed arguments.
a) va_arg
b) va_end
c) va_list
d) va_start
View Answer

Answer: d
Explanation: va_start macro shall be invoked before any access to the unnamed arguments.void va-start (va-list ap, p); The va-start macro initializes ap for subsequent use by va-arg and va-end.
advertisement

7. ______ macro must be called before using ______ and ________
a) va_arg, va_end and va_start
b) va_start, va_end and va_arg
c) va_end, va_arg and va_start
d) v_arg, v_end and v_start
View Answer

Answer: b
Explanation: va_start macro must be called before using macros va_end and va_arg.
The macro void va_start(va_list p, last_arg) initializes p variable to be used with the va_arg and va_end macros.

8. The C library macro type _________ retrieves the next argument in the parameter list of the function with type.
a) va_end
b) va_arg
c) va_start
d) no macros
View Answer

Answer: b
Explanation: va_arg is the C library macro defined under stdarg.h which retrieves the next argument in the parameter list of the function.
advertisement

9. What is the role of the given C function?

void va_end(va_list ap)

a) allows a function with variable arguments which used the va_start macro to return
b) retrieves the next argument in the parameter list
c) initializes ap variable to be used with the va_arg and va_start macros
d) returns the next additional argument as an expression
View Answer

Answer: a
Explanation: void va_end(va_list ap) defined under the header file stdarg allows a function with variable arguments which used the va_start macro to return.
The result is undefined if va_end is not called before returning from the function.

10. Which header file should be included if a function has to be defined such that it can accept variable number of arguments?
a) stdlib.h
b) stdarg.h
c) assert.h
d) setjmp.h
View Answer

Answer: b
Explanation: stdarg.h is the header file which should be included if a function has to be defined such that it can accept variable number of arguments.

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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

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
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.