ProgrammingHardTCS Digital · Capgemini
What will be the output of the following pseudocode? (integers are two's complement; ~ is bitwise NOT; >> is an arithmetic shift that keeps the sign)
What will be the output of the following pseudocode? (integers are two's complement; ~ is bitwise NOT; >> is an arithmetic shift that keeps the sign)
Integer a = 5, b = -1, c = -16 Print ~a, ~b, c >> 2
- A. -6 0 -4
- B. -5 1 -4
- C. -5 0 -4
- D. 250 0 -4
Correct answer: A. -6 0 -4
In two's complement ~x = −x − 1, so ~5 = −6 and ~(−1) = 0. An arithmetic right shift keeps the sign: −16 >> 2 = −4. Output -6 0 -4.
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 n = 19, steps = 0, s…
- What will be the output of the following pseudocode? Integer u[1..10], i2 = 1, i3 = 1, i5 = 1, nx u[1] = 1 for (each k from 2 to 10) nx =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 50, lo = 0, hi =…
- What will be the output of the following pseudocode? (operands are evaluated left to right; arrays are indexed from 0) Integer q[5], front…
- What will be the output of the following pseudocode? String in = "A+BC-D/E", out = "" Stack st = empty // prec: and / are 2, + and - are 1…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; heap[k / 2] is the parent of…