GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 2.5

FORTRAN mixed arithmetic and integer assignment

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 1993 paper

GATE 1993, Q2.5 Other
Report issue

Semantic Analysis & Type Checking

Question 2.5, GATE 1993: For X=4.0, evaluate integer I assigned −2**2+(5.0*X)/(X*3)+3/4, following the displayed fraction grouping.
Tap to enlarge
Answer & solution

Answer: −2 (no official key was published)

Exponentiation binds before unary negation, so −2**2 is −4, not +4. The middle term is real arithmetic: 20.0/12.0=5/3. The literal operands in 3/4 are integers, so FORTRAN integer division gives zero. The resulting real value is −4+5/3=−7/3. Assignment to integer I truncates toward zero, yielding −2. The printed source uses two-dimensional fractions rather than literal FORTRAN source; the grouping in the paraphrase is stated explicitly so a flattened division/multiplication expression is not silently substituted.

Original paper, page 2