MCQs
Total Questions : 25
| Page 2 of 3 pages
Answer: Option A. -> True
Answer: Option A. -> True
Answer: Option A. -> True
Answer: Option B. -> False
Answer: Option C. -> Error: ptr must be type of va_list
Question 16.
#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
void show(char *t, ...);
int main()
{
display("Hello", 4, 12, 13, 14, 44);
return 0;
}
void display(char *s, ...)
{
show(s, ...);
}
void show(char *t, ...)
{
int a;
va_list ptr;
va_start(ptr, s);
a = va_arg(ptr, int);
printf("%f", a);
}
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
void show(char *t, ...);
int main()
{
display("Hello", 4, 12, 13, 14, 44);
return 0;
}
void display(char *s, ...)
{
show(s, ...);
}
void show(char *t, ...)
{
int a;
va_list ptr;
va_start(ptr, s);
a = va_arg(ptr, int);
printf("%f", a);
}
Answer: Option B. -> Error: invalid function show() call
The call to show() is improper. This is not the way to pass variable argument list to a function.
Answer: Option B. -> Error: var c data type mismatch
Use double instead of float in float c;
Use double instead of float in float c;
Question 18.
#include<stdio.h>
#include<stdarg.h>
int main()
{
void display(char *s, int num1, int num2, ...);
display("Hello", 4, 2, 12.5, 13.5, 14.5, 44.0);
return 0;
}
void display(char *s, int num1, int num2, ...)
{
double c;
char s;
va_list ptr;
va_start(ptr, s);
c = va_arg(ptr, double);
printf("%f", c);
}
Point out the error in the following program.
#include<stdio.h>
#include<stdarg.h>
int main()
{
void display(char *s, int num1, int num2, ...);
display("Hello", 4, 2, 12.5, 13.5, 14.5, 44.0);
return 0;
}
void display(char *s, int num1, int num2, ...)
{
double c;
char s;
va_list ptr;
va_start(ptr, s);
c = va_arg(ptr, double);
printf("%f", c);
}
Answer: Option C. -> Error: in va_start(ptr, s);
We should have use va_start(ptr, num2);
Answer: Option A. -> Error: ptr has to be set at begining
Using va_start(ptr, int);
Answer: Option C. -> No error and print A a b c