This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Variable Length Argument – 1”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. What will be the output of the following C code?
#include <stdio.h>
#include <stdarg.h>
void func(int, ...);
int main()
{
func(2, 3, 5, 7, 11, 13);
return 0;
}
void func(int n, ...)
{
int number, i = 0;
va_list start;
va_start(start, n);
while (i != 3)
{
number = va_arg(start, int);
i++;
}
printf("%d", number);
}
a) 3
b) 5
c) 7
d) 11
View Answer
Explanation: None.
2. Which of the following function with ellipsis are illegal?
a) void func(…);
b) void func(int, …);
c) void func(int, int, …);
d) none of the mentioned
View Answer
Explanation: None.
3. Which of the following data-types are promoted when used as a parameter for an ellipsis?
a) char
b) short
c) int
d) none of the mentioned
View Answer
Explanation: None.
4. Which header file includes a function for variable number of arguments?
a) stdlib.h
b) stdarg.h
c) ctype.h
d) both stdlib.h and stdarg.h
View Answer
Explanation: None.
5. Which of the following macro extracts an argument from the variable argument list (ie ellipsis) and advance the pointer to the next argument?
a) va_list
b) va_arg
c) va_end
d) va_start
View Answer
Explanation: None.
6. The type va_list in an argument list is used ________
a) To declare a variable that will refer to each argument in turn;
b) For cleanup
c) To create a list
d) There is no such type
View Answer
Explanation: None.
7. In a variable length argument function, the declaration “…” can _______
a) Appear anywhere in the function declaration
b) Only appear at the end of an argument list
c) Nothing
d) None of the mentioned
View Answer
Explanation: None.
8. Each call of va_arg _______
a) Returns one argument
b) Steps va_list variable to the next
c) Returns one argument & Steps va_list variable to the next
d) None of the mentioned
View Answer
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.
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy Computer Science Books
- Buy C Books
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Watch Advanced C Programming Videos