GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 2.4

A value parameter shadows a global

Compiler Design · Runtime Environments & Parameter Passing · Full GATE CSE 1995 paper

GATE 1995, Q2.4 2 marks · MCQ
Report issue

Runtime Environments & Parameter Passing

Question 2.4, GATE 1995: Pascal has global integer X=2 and procedure FIND(X:real) assigning X:=sqrt(X). After FIND(X), what does printing global X produce?
Tap to enlarge
Your answer
Answer & solution

Answer: A: 2 under the intended Pascal value-parameter program (no official key was published)

Without the keyword var, the procedure parameter is passed by value. Its local X receives a real copy of the argument and shadows the global name inside FIND. Assigning sqrt(X) changes only that local copy; it does not assign to the global integer. On return the global X is still 2, so printing it yields 2. The the paper omits some statement separators; this analysis uses the intended syntactically separated program rather than treating formatting omissions as executable Pascal.

Original paper, page 3