ProgrammingHardCapgemini · Cognizant GenC Next
What will be the output of the following pseudocode? (XOR is true when exactly one side is true; NOT binds tighter than AND, which binds tighter than OR)
What will be the output of the following pseudocode? (XOR is true when exactly one side is true; NOT binds tighter than AND, which binds tighter than OR)
Boolean p = true, q = false, r = true Print (p XOR q) AND NOT (q OR r), (p AND q) OR (NOT p OR r), p XOR q XOR r
- A. true true true
- B. false false true
- C. false true false
- D. true false false
Correct answer: C. false true false
(true XOR false) = true, but NOT (false OR true) = false, so the first is false. (false) OR (false OR true) = true. true XOR false XOR true = false. Output false true false.
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 a[6] = {3, 8, 1, 9, 4, 7} Integer best = -1, i = 0, j = 5 while (i < j) best…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division) Integer n = 37, ones = 0…
- What will be the output of the following pseudocode? Integer a[5] = {2, 4, 1, 3, 5}, c = 0 for (each i from 0 to 3) for (each j from i + 1…
- Activities are given as (start, finish): (1,4) (3,5) (0,6) (5,7) (3,9) (5,9) (6,10) (8,11) (8,12) (2,14) (12,16). The procedure below runs…
- Five jobs each take one time unit. Job (name, deadline, profit): a (2,100), b (1,19), c (2,27), d (1,25), e (3,15). A job earns its profit…
- Train (arrival, departure) times in HHMM form: arrivals 900, 940, 950, 1100, 1500, 1800 and departures 910, 1200, 1120, 1130, 1900, 2000…