Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <stdarg.h>
using namespace std;
float avg( int Count, ... )
{
    va_list Numbers;
    va_start(Numbers, Count);
    int Sum = 0;
    for (int i = 0; i < Count; ++i)
        Sum += va_arg(Numbers, int);
    va_end(Numbers);
    return (Sum/Count);
}
int main()
{
    float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    cout << Average;
    return 0;
}

A. 4

B. 5

C. 6

D. compile time error

Answer: Option A


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it