Sail E0 Webinar

MCQs

Total Questions : 9
Question 1.

What will initialize the list of arguments in stdarg.h header file?


  1.    va_list
  2.    va_start
  3.    va_arg
  4.    none of the mentioned
 Discuss Question
Answer: Option B. -> va_start

None.


Question 2.

Which header file should you include if you are to develop a function that can accept variable 

number of arguments?


  1.    varag.h
  2.    stdlib.h
  3.    stdio.h
  4.    stdarg.h
 Discuss Question
Answer: Option D. -> stdarg.h

None.


Question 3.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int flue(char c,...);
5.
int main()
6.
{
7.
int x, y;
8.
x = flue('A', 1, 2, 3);
9.
y = flue('1', 1.0,1, '1', 1.0f, 1l);
10.
cout
  1.    6549
  2.    4965
  3.    6646
  4.    compile time error
 Discuss Question
Answer: Option A. -> 6549

In this program, we are returning the ascii value of the character and printing it.
Output:
$ g++ rka4.cpp
$ a.out
6549


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
void dumplist(int, ...);
5.
int main()
6.
{
7.
dumplist(2, 4, 8);
8.
dumplist(3, 6, 9, 7);
9.
return 0;
10.
}
11.
void dumplist(int n, ...)
12.
{
13.
va_list p;
14.
int i;
15.
va_start(p, n);
16.
while (n-->0) {
17.
i = va_arg(p, int);
18.
cout
  1.    2436
  2.    48697
  3.    1111111
  4.    compile time error
 Discuss Question
Answer: Option B. -> 48697

In this program, we are eradicating the first value
by comparing using while operator.
Output:
$ g++ rka3.cpp
$ a.out
48697


Question 5.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int add (int num, ...)
5.
{
6.
int sum = 0;
7.
va_list args;
8.
va_start (args,num);
9.
for (int i = 0; i < num; i++) {
10.
int num = va_arg (args,int);
11.
sum += num;
12.
}
13.
va_end (args);
14.
return sum;
15.
}
16.
int main (void)
17.
{
18.
int total = add(8, 1, 2, -1, 4, 12, -2, 9, 7);
19.
cout
  1.    32
  2.    23
  3.    48
  4.    compile time error
 Discuss Question
Answer: Option A. -> 32

We are adding these numbers by using for statement and stdarg.
Output:
$ g++ uka.cpp
$ a.out
The result is 32


Question 6.

What is the maximum number of arguments or parameters that can be
present in one function call?


  1.    64
  2.    256
  3.    255
  4.    16
 Discuss Question
Answer: Option B. -> 256

None.


Question 7.

How can you access the arguments that are manipulated in the function?


  1.    va_list
  2.    arg_list
  3.    both a & b
  4.    none of the mentioned
 Discuss Question
Answer: Option A. -> va_list

None.


Question 8.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
float avg( int Count, ... )
5.
{
6.
va_list Numbers;
7.
va_start(Numbers, Count);
8.
int Sum = 0;
9.
for (int i = 0; i < Count; ++i )
10.
Sum += va_arg(Numbers, int);
11.
va_end(Numbers);
12.
return (Sum/Count);
13.
}
14.
int main()
15.
{
16.
float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
17.
cout
  1.    4
  2.    5
  3.    6
  4.    7
 Discuss Question
Answer: Option A. -> 4

We are just calculating the average of these numbers using cstdarg.
Output:
$ g++ uka.cpp
$ a.out
Average of first 10 whole numbers 4


Question 9.

Which header file is used to pass unknown number of arguments to function?


  1.    stdlib.h
  2.    string.h
  3.    stdarg.h
  4.    none of the mentioned
 Discuss Question
Answer: Option C. -> stdarg.h

Because the cstdarg defines this header file to process the unknown number of arguments.


Latest Videos

Latest Test Papers