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- A. 80 97 53
- B. 112 65 53
- C. 112 65 21
- 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.
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? (| is OR, & is AND, << and >> are shifts) String s = "THE QUICK BROWN FOX" Integer…
- What will be the output of the following pseudocode? (Arrays are indexed from 0; abs gives the absolute value) Integer a[8] = {4, 3, 2, 7…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[4] = {3, 4, -1, 1}, n = 4 for (each i from 0 to…
- What will be the output of the following pseudocode? (Arrays are indexed from 0) Integer a[3] = {1, 3, 8}, b[4] = {2, 7, 9, 10}, c[7]…
- What will be the output of the following pseudocode? Integer m[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} for (each i from 0 to…
- What will be the output of the following pseudocode? (/ is integer division) String tok[9] = {"-", "", "+", "2", "3", "4", "/", "8", "2"}…