106k views
3 votes
What will the following segment of code output if 11 is entered at the keyboard? int number; cin >> number; if (number > 0) cout << "C++"; else cout << "Soccer"; cout << " is "; cout << "fun" << endl; 1. C++ is fun 2. Soccer is fun 3. C++ 4. C++fun 5. Soccerfun

User Shipr
by
5.6k points

1 Answer

2 votes

Answer:

1. C++ is fun

Step-by-step explanation:

Writing the code more clear:

int number;

cin >> number;

if (number > 0)

cout << "C++";

else

cout << "Soccer";

cout << " is ";

cout << "fun" << endl;

On the IF line, the conditional expression is evaluated TRUE (11 > 0), so the string "C++" is printed.

Then, the ELSE sentence is not executed since the expression has been already evaluated as TRUE.

Notice there are no additional brackets, so only the line cout << "Soccer"; is considered inside the ELSE.

The two remaining lines are executed always.

The final result is:

C++ is fun

User Parvez Rahaman
by
5.7k points