ProgrammingHardInfosys SP · TCS Digital

What will be the output of the following pseudocode? (code(c) gives the ASCII code: 'A' = 65, 'a' = 97, '0' = 48; ^ is XOR)

What will be the output of the following pseudocode? (code(c) gives the ASCII code: 'A' = 65, 'a' = 97, '0' = 48; ^ is XOR)
Integer x = code('P') ^ 32
Integer y = code('a') ^ 32
Integer z = code('5') ^ 32
Print x, y, z
  1. A. 80 97 53
  2. B. 112 65 53
  3. C. 112 65 21
  4. D. 112 129 85

Correct answer: C. 112 65 21

In ASCII, the upper- and lower-case forms of a letter differ only in the bit worth 32, so XOR with 32 toggles case: 'P' (80) → 112 ('p') and 'a' (97) → 65 ('A'). XOR is not addition, and it flips that bit in any character: '5' (53 = 0110101) → 21. Output 112 65 21.

More Pseudocode and Code Tracing questions

Exams that ask this topic