C MCQs: Variable Length Arguments- Part 2

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>

2. va_end does whatever.
a) Cleanup is necessary
b) Bust be called before the program returns.
c) Both a &
d) None of the mentioned

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

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

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

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


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

 Next –> C MCQs: File Access- Part 1

Leave a Comment