C Questions and Answers – Variable Argument Lists

«
»

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

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.
advertisement

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.

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.

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.
advertisement

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.

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.

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

advertisement
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.

advertisement

advertisement
advertisement
advertisement

Leave a Comment

Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn