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.
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. 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
Explanation: None.
3. What will be the output of the following 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 will be the output of the following 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 will be the output of the following 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 will be the output of the following 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 will be the output of the following 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.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for C Internship
- Practice Computer Science MCQs
- Practice BCA MCQs
- Apply for Computer Science Internship
- Check C Books