250+ TOP MCQs on Variable Length Argument and Answers

C helps anyone preparing for Toshiba and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Toshiba interviews on C Programming language.

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?

  1.     #include 
  2.     int f(char chr, ...);
  3.     int main()
  4.     {
  5.         char c = 97;
  6.         f(c);
  7.         return 0;
  8.     }
  9.     int f(char c, ...)
  10.     {
  11.         printf("%cn", c);
  12.     }

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?

  1.     #include 
  2.     #include 
  3.     int f(...);
  4.     int main()
  5.     {
  6.         char c = 97;
  7.         f(c);
  8.         return 0;
  9.     }
  10.     int f(...)
  11.     {
  12.         va_list li;
  13.         char c = va_arg(li, char);
  14.         printf("%cn", c);
  15.     }

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?

  1.     #include 
  2.     #include 
  3.     int f(char c, ...);
  4.     int main()
  5.     {
  6.         char c = 97, d = 98;
  7.         f(c, d);
  8.         return 0;
  9.     }
  10.     int f(char c, ...)
  11.     {
  12.         va_list li;
  13.         va_start(li, c);
  14.         char d = va_arg(li, char);
  15.         printf("%cn", d);
  16.         va_end(li);
  17.     }

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?

  1.     #include 
  2.     #include 
  3.     int f(char c, ...);
  4.     int main()
  5.     {
  6.         char c = 97, d = 98;
  7.         f(c, d);
  8.         return 0;
  9.     }
  10.     int f(char c, ...)
  11.     {
  12.         va_list li;
  13.         va_start(li, c);
  14.         char d = va_arg(li, int);
  15.         printf("%cn", d);
  16.         va_end(li);
  17.     }

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?

  1.     #include 
  2.     #include 
  3.     int f(int c, ...);
  4.     int main()
  5.     {
  6.         int c = 97;
  7.         float d = 98;
  8.         f(c, d);
  9.         return 0;
  10.     }
  11.     int f(int c, ...)
  12.     {
  13.         va_list li;
  14.         va_start(li, c);
  15.         float d = va_arg(li, float);
  16.         printf("%fn", d);
  17.         va_end(li);
  18.     }

a) Compile time error
b) Undefined behaviour
c) 97.000000
d) 98.000000
Answer: b
Clarification: None.

Leave a Reply

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