Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void Sum(int a, int b, int & c)
{
    a = b + c;
    b = a + c;
    c = a + b;
}
int main()
{
    int x = 2, y =3;
    Sum(x, y, y);
    cout << x << " " << y;
    return 0;
}

A. 2 3

B. 6 9

C. 2 15

D. compile time error

Answer: Option C


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