MCQs
Total Questions : 9
Answer: Option B. -> va_start
None.
Answer: Option D. -> stdarg.h
None.
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.
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
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
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.
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
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
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
Answer: Option B. -> 256
None.
Answer: Option A. -> va_list
None.
Question 8.
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
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
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
Answer: Option C. -> stdarg.h
Because the cstdarg defines this header file to process the unknown number of arguments.