ProgrammingVery hardTCS NQT Advanced · Capgemini
What will be the output of the following pseudocode? (operands are evaluated strictly left to right)
What will be the output of the following pseudocode? (operands are evaluated strictly left to right)
Integer a = 7, b = 3 a = a + b - (b = a) // the inner assignment happens when that operand is evaluated Print a, b
- A. 3 7
- B. 7 3
- C. 10 7
- D. 4 7
Correct answer: A. 3 7
Evaluated left to right: a + b = 10 is computed first, then (b = a) sets b to 7 and yields 7. So a = 10 − 7 = 3 and b = 7: the values are swapped, 3 7.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? Integer calls = 0 Function C(Integer n, Integer k) calls = calls + 1 if (k == 0 OR k…
- What will be the output of the following pseudocode? // Integer16: 16-bit signed integers in two's complement; results wrap around…
- What will be the output of the following pseudocode? Record r[4] = {(3, 'a'), (1, 'b'), (3, 'c'), (1, 'd')} // (key, letter) for (each i…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[7] = {4, 2, 2, 8, 3, 3, 1}, cnt[0..8] = all 0…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[8] = {170, 45, 75, 90, 802, 24, 2, 66} List…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer lo = 1, hi = 1000…