Here is a listing of C interview 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) <stdio.h >
b) <stdlib.h>
c) <math.h>
d) <stdarg.h>
View Answer
Explanation: None.
2. va_end does whatever.
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
View Answer
Explanation: None.
3. What is the output of this C code?
#include <stdio.h>
int f(char chr, ...);
int main()
{
char c = 97;
f(c);
return 0;
}
int f(char c, ...)
{
printf("%c\n", c);
}
a) Compile time error
b) Undefined behaviour
c) 97
d) a
View Answer
Explanation: None.
4. What is the output of this C code?
#include <stdio.h>
#include <stdarg.h>
int f(...);
int main()
{
char c = 97;
f(c);
return 0;
}
int f(...)
{
va_list li;
char c = va_arg(li, char);
printf("%c\n", c);
}
a) Compile time error
b) Undefined behaviour
c) 97
d) a
View Answer
Explanation: None.
5. What is the output of this C code?
#include <stdio.h>
#include <stdarg.h>
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("%c\n", d);
va_end(li);
}
a) Compile time error
b) Undefined behaviour
c) a
d) b
View Answer
Explanation: None.
6. What is the output of this C code?
#include <stdio.h>
#include <stdarg.h>
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("%c\n", d);
va_end(li);
}
a) Compile time error
b) Undefined behaviour
c) a
d) b
View Answer
Explanation: None.
7. What is the output of this C code?
#include <stdio.h>
#include <stdarg.h>
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("%f\n", d);
va_end(li);
}
a) Compile time error
b) Undefined behaviour
c) 97.000000
d) 98.000000
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – C Programming Language.
Here’s the list of Best Reference Books in C Programming Language.
To practice all features of C programming language, here is complete set of 1000+ Multiple Choice Questions and Answers on C.