Sail E0 Webinar
Question


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
Options:
A .  32
B .  23
C .  48
D .  compile time error
Answer: Option A

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



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers