250+ TOP MCQs on Variable Argument Lists and Answers

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

1. How many macros are defined in the header file stdarg.h?
a) one
b) two
c) three
d) four
Answer: c
Clarification: 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
Answer: a
Clarification: 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()
Answer: c
Clarification: 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
Answer: b
Clarification: 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)
Answer: a
Clarification: 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
Answer: d
Clarification: 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
Answer: b
Clarification: 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
Answer: b
Clarification: 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?

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

contest

Leave a Reply

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