GATE / CS ARCHIVE

GATE CSE 1991 / QUESTION 4(i)

Replacing a Boolean conditional assignment

Programming in C · Control Flow & Loop Tracing · Full GATE CSE 1991 paper

GATE 1991, Q4(i) 2 marks · Descriptive
Report issue

Control Flow & Loop Tracing

Question 4(i), GATE 1991: Replace Pascal if x>5 then y:=true else y:=false with one assignment.
Question 4(i), GATE 1991: Replace Pascal if x>5 then y:=true else y:=false with one assignment.
Tap to enlarge
Answer & solution

Answer: y := (x > 5); (no official key was published)

The comparison x>5 evaluates to a Boolean. In the true case, the original statement assigns true to y; in the false case, it assigns false. Assigning the comparison result therefore gives exactly the same value in both cases. At x=5, the result is false, so using ≥ instead would be incorrect. This simplification assumes y has Boolean type and the comparison has the ordinary Pascal semantics shown in the source. No branch or numeric Boolean encoding is needed.

Original paper, page 5