adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    #include <stdarg.h>
    using namespace std;
    int add (int num, ...)
    {
        int sum = 0;
        va_list args;
        va_start (args,num);
        for (int i = 0; i < num; i++) 
        {
            int num = va_arg (args,int);
            sum += num;
        }
        va_end (args);
        return sum;
    }
    int main (void)
    {
        int total = add(8, 1, 2, -1, 4, 12, -2, 9, 7);
        cout << "The result is " << total;
        return 0;
    }

a.

32

b.

23

c.

48

d.

compile time error

Answer: (a).32

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?