OA. free
Free
TCS Data Structures & Algorithms Data Structures & Algorithms Medium

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 using namespace std; int main() { int a=5,b=0,c=15,d=20,e=0; while(a<b) e=(a+c)*d+c; cout<<e<<""<<b; return 0; } Ans:- B) 0 0 218 TCS NQT Solved Paper - 13th Sept 2021 [Slot 1] - A) 420 0 - B) 0 0 - C) 420 10 - D) 0 10

Choose one option.
Show answer & explanation
Answer: B. 0 0

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'.