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
  1. A. true true true
  2. B. false false true
  3. C. false true false
  4. 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.

More Pseudocode and Code Tracing questions

Exams that ask this topic