ProgrammingModerateCapgemini · Infosys pattern
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Integer a = 1, b = 2, c = 3 a = b + c b = a - b * c c = a * b - c Print a + b + c
- A. -4
- B. -2
- C. 6
- D. 4
Correct answer: A. -4
Each line uses the values updated just before it: a = 5, b = 5 - 2 × 3 = -1, c = 5 × (-1) - 3 = -8. Sum = 5 - 1 - 8 = -4. The usual slip is using the old b = 2 in the last line, which gives c = 7 instead of -8.
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? (All variables are integers, so / is integer division.) Integer s = 0 for (each i…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division.) Integer n = 100, c = 0, d = 5…
- What will be the output? (calls counts every call, including the first.) Integer calls = 0 Function fun(Integer a, Integer b) calls =…
- What will be the output of the following pseudocode? Integer c = 0 for (i = 1; i < 64; i = i 2) for (j = i; j < 64; j = j + i) c = c + 1…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…
- What will be the output of the following pseudocode? (& is bitwise AND, | is bitwise OR, ^ is bitwise XOR, << and >> are left and right…