Here is a listing of C Objective Questions on “Variable Length Argument” along with answers, explanations and/or solutions:
1. The standard header _______ is used for variable list arguments (…) in C.
a)
b)
c)
d)
Answer: d
Clarification: None.
2. What is the purpose of va_end?
a) Cleanup is necessary
b) Must be called before the program returns
c) Cleanup is necessary & Must be called before the program returns
d) None of the mentioned
Answer: c
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
int f(char chr, ...);
-
int main()
-
{
-
char c = 97;
-
f(c);
-
return 0;
-
}
-
int f(char c, ...)
-
{
-
printf("%cn", c);
-
}
a) Compile time error
b) Undefined behaviour
c) 97
d) a
Answer: d
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
#include
-
int f(...);
-
int main()
-
{
-
char c = 97;
-
f(c);
-
return 0;
-
}
-
int f(...)
-
{
-
va_list li;
-
char c = va_arg(li, char);
-
printf("%cn", c);
-
}
a) Compile time error
b) Undefined behaviour
c) 97
d) a
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
#include
-
int f(char c, ...);
-
int main()
-
{
-
char c = 97, d = 98;
-
f(c, d);
-
return 0;
-
}
-
int f(char c, ...)
-
{
-
va_list li;
-
va_start(li, c);
-
char d = va_arg(li, char);
-
printf("%cn", d);
-
va_end(li);
-
}
a) Compile time error
b) Undefined behaviour
c) a
d) b
Answer: b
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
#include
-
int f(char c, ...);
-
int main()
-
{
-
char c = 97, d = 98;
-
f(c, d);
-
return 0;
-
}
-
int f(char c, ...)
-
{
-
va_list li;
-
va_start(li, c);
-
char d = va_arg(li, int);
-
printf("%cn", d);
-
va_end(li);
-
}
a) Compile time error
b) Undefined behaviour
c) a
d) b
Answer: d
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
#include
-
int f(int c, ...);
-
int main()
-
{
-
int c = 97;
-
float d = 98;
-
f(c, d);
-
return 0;
-
}
-
int f(int c, ...)
-
{
-
va_list li;
-
va_start(li, c);
-
float d = va_arg(li, float);
-
printf("%fn", d);
-
va_end(li);
-
}
a) Compile time error
b) Undefined behaviour
c) 97.000000
d) 98.000000
Answer: b
Clarification: None.