Question 7: What will be the output of the following code include <iostream using namespace...
TCS technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What will be the output of the following code #include
Show answer & explanation
The while loop condition (a < b) is evaluated as (5 < 0), which is false. Consequently, the loop body is never executed, and the initial value of 'e' (0) and 'b' (0) are printed.
Step-by-step Derivation:
Step 1: Initialize variables: a = 5, b = 0, c = 15, d = 20, e = 0.
Step 2: Evaluate the while loop condition: (a < b) => (5 < 0). This expression evaluates to false.
Step 3: Since the condition is false, the statement inside the loop 'e = (a + c) * d + c' is skipped entirely.
Step 4: Execute the output statement: cout << e << "" << b;.
Step 5: Substitute the current values: e is 0 and b is 0.
Step 6: The output is '0 0'.