Write the output of the following cout statements, showing the
steps of your work.
auto value_1 = -1, value_2 = -4, value_3 = 9;
if (value_1 == value_2 || value_3 / 3 > value_2)
{
if (value_1 - 2 * value_2 == 1)
cout << "A";
else if (value_3 * -1 > 0)
cout << "B";
} else {
cout << "C"; }
Answer:
This will code print nothing, as it may show the "Program finished with exit code 0 " on the console window.
Explanation:
We will run code line by line.
Given values, auto value_1 = -1, value_2 = -4, value_3 = 9;
if (value_1 == value_2 || value_3 / 3 > value_2) that is (-1 == -4 || 9/3 > -4) condition is true as 3>-4 will move into if.
now check inner if statement
if (value_1 - 2 * value_2 == 1) i.e. (-1 -2 * -4 == 1 ) which is false as (7 !=1)
so will move to else if condition.
else if (value_3 * -1 > 0) i.e. (9 * -1 > 0) which is false as -8 is not greater than 0
As we can see that there is no else statement, so it would print nothing and program will exit with code 0.
Note: It would not also print C as outer if condition is true, so will not go to else.
Please give thumbsup, or do comment in case of any query. Thanks.
Get Answers For Free
Most questions answered within 1 hours.