Exercise: Variable Number Of Arguments

Questions for: Variable Number Of Arguments

For a function receives variable number of arguments it is necessary that the function should receive at least one fixed argument.
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
A function that receives variable number of arguments should use va_arg() to extract arguments from the variable argument list.
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
In a function that receives variable number of arguments the fixed arguments passed to the function can be at the end of argument list.
A:
True
B:
False
C:
D:
Answer: B
No answer description is available. Let's discuss.
The macro va_arg is used to extract an argument from the variable argument list and advance the pointer to the next argument.
A:
True
B:
False
C:
D:
Answer: A
No answer description is available. Let's discuss.
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
void varfun(int n, ...);

int main()
{
    varfun(3, 7, -11.2, 0.66);
    return 0;
}
void varfun(int n, ...)
{
    float *ptr;
    int num;
    va_start(ptr, n);
    num = va_arg(ptr, int);
    printf("%d", num);
}
A:
Error: too many parameters
B:
Error: invalid access to list member
C:
Error: ptr must be type of va_list
D:
No error
Answer: C
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz