138k views
1 vote
What would the output be?

int a = 3, b = 2, c = 5
if (a > b)
a = 4;
if ( b > c)
a = 5;
else
a = 6;
cout << a < endl;
C++ Programming: Program Design Including Data Structures, Seventh Edition 32
a) 3
b) 4
c) 5
d) 6

User Dum Potato
by
7.8k points

1 Answer

2 votes

Final answer:

The output for the given code would be 4.

Step-by-step explanation:

The output for the given code would be 4.

The code first checks if a is greater than b. Since 3 is greater than 2, the first condition is satisfied.

Then, the code proceeds to check if b is greater than c. Since 2 is not greater than 5, this condition is not satisfied.

Finally, the else condition is executed, which assigns the value 4 to a. Therefore, the output will be 4.

User Hunger
by
7.9k points