C Programming Questions and Answers – Variable Length Argument – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Variable Length Argument – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

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

Answer: d
Explanation: 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
View Answer

Answer: c
Explanation: None.
Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement

3. What will be the output of the following C code?

  1.     #include <stdio.h>
  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("%c\n", c);
  12.     }

a) Compile time error
b) Undefined behaviour
c) 97
d) a
View Answer

Answer: d
Explanation: None.
advertisement

4. What will be the output of the following C code?

advertisement
  1.     #include <stdio.h>
  2.     #include <stdarg.h>
  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("%c\n", c);
  15.     }

a) Compile time error
b) Undefined behaviour
c) 97
d) a
View Answer

Answer: a
Explanation: None.
advertisement

5. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     #include <stdarg.h>
  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("%c\n", d);
  16.         va_end(li);
  17.     }

a) Compile time error
b) Undefined behaviour
c) a
d) b
View Answer

Answer: b
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     #include <stdarg.h>
  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("%c\n", d);
  16.         va_end(li);
  17.     }

a) Compile time error
b) Undefined behaviour
c) a
d) b
View Answer

Answer: d
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     #include <stdarg.h>
  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("%f\n", d);
  17.         va_end(li);
  18.     }

a) Compile time error
b) Undefined behaviour
c) 97.000000
d) 98.000000
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement

Leave a Comment

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.