What is the output of the following C++ program segment, called with confuseDriver() ?
A) s + y = 3
B) s + y = 6
C) s + y = 8
D) s + y = 10
int s=1, y=3;
void confuse1(int y, int s)
{
s++;
y++;
}
void confuse2(int b, int &s)
{
y = ++(s);
s = b;
}
void confuse3(int &a, int &s)
{
a = s + 1;
s++;
}
void confuseDriver()
{
int s=2;
confuse1( s, y);
confuse2( s, y);
confuse3( s, y);
cout << "s + y = " << s+y << endl;
}

Q&A Education