Sail E0 Webinar

MCQs

Total Questions : 25 | Page 2 of 3 pages
Question 11.

For a function receives variable number of arguments it is necessary that the function 

should receive at least one fixed argument.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True


Question 12.

A function that receives variable number of arguments should use va_arg() to extract 

arguments from the variable argument list.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True


Question 13.

The macro va_arg is used to extract an argument from the variable argument list and 

advance the pointer to the next argument.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True


Question 14.

In a function that receives variable number of arguments the fixed arguments passed to 

the function can be at the end of argument list.


  1.    True
  2.    False
 Discuss Question
Answer: Option B. -> False


Question 15.


Point out the error in the following program.


#include<stdio.h>
#include<stdarg.h>
void varfun(int n, ...);
int main()
{
varfun(3, 7, -11.2, 0.66);
return 0;
}
void varfun(int n, ...)
{
float *ptr;
int num;
va_start(ptr, n);
num = va_arg(ptr, int);
printf("%d", num);
}
  1.    Error: too many parameters
  2.    Error: invalid access to list member
  3.    Error: ptr must be type of va_list
  4.    No error
 Discuss Question
Answer: Option C. -> Error: ptr must be type of va_list


Question 16.


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);
}
  1.    Error: invalid function display() call
  2.    Error: invalid function show() call
  3.    No error
  4.    Error: Rvalue required for t
 Discuss Question
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.


Question 17.


Point out the error in the following program.


#include<stdio.h>
#include<stdarg.h>
int main()
{
void display(int num, ...);
display(4, 12.5, 13.5, 14.5, 44.3);
return 0;
}
void display(int num, ...)
{
float c; int j;
va_list ptr;
va_start(ptr, num);
for(j=1; j
  1.    Error: invalid va_list declaration
  2.    Error: var c data type mismatch
  3.    No error
  4.    No error and Nothing will print
 Discuss Question
Answer: Option B. -> Error: var c data type mismatch

Use double instead of float in float c;
Question 18.


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);
}
  1.    Error: invalid arguments in function display()
  2.    Error: too many parameters
  3.    Error: in va_start(ptr, s);
  4.    No error
 Discuss Question
Answer: Option C. -> Error: in va_start(ptr, s);

We should have use va_start(ptr, num2);


Question 19.


Point out the error in the following program.


#include<stdio.h>
#include<stdarg.h>
void varfun(int n, ...);
int main()
{
varfun(3, 7, -11, 0);
return 0;
}
void varfun(int n, ...)
{
va_list ptr;
int num;
num = va_arg(ptr, int);
printf("%d", num);
}
  1.    Error: ptr has to be set at begining
  2.    Error: ptr must be type of va_list
  3.    Error: invalid access to list member
  4.    No error
 Discuss Question
Answer: Option A. -> Error: ptr has to be set at begining

Using va_start(ptr, int);


Question 20.


Point out the error if any in the following program (Turbo C).


#include<stdio.h>
#include<stdarg.h>
void display(int num, ...);
int main()
{
display(4, 'A', 'a', 'b', 'c');
return 0;
}
void display(int num, ...)
{
char c; int j;
va_list ptr;
va_start(ptr, num);
for(j=1; j
  1.    Error: unknown variable ptr
  2.    Error: Lvalue required for parameter
  3.    No error and print A a b c
  4.    No error and print 4 A a b c
 Discuss Question
Answer: Option C. -> No error and print A a b c


Latest Videos

Latest Test Papers