GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 7.2

A value parameter does not modify its actual expression

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

GATE 1993, Q7.2 2 marks · MSQ
Report issue

Runtime Environments & Parameter Passing

Question 7.2, GATE 1993: Global n=0. Q(x:integer;var y:integer) executes x:=y+1. What is printed after Q(n*1,n)?
Question 7.2, GATE 1993: Global n=0. Q(x:integer;var y:integer) executes x:=y+1. What is printed after Q(n*1,n)?
Tap to enlarge
Select all that apply
Answer & solution

Answer: B: 0 (no official key was published)

The actual n*1 is evaluated to zero and copied into value parameter x. Parameter y is a reference to n. The assignment computes y+1=1 but writes only the local copy x; it never assigns to y. Thus n remains zero and the caller prints zero. Calling with an expression as the first actual is valid precisely because that parameter has value semantics; a reference formal would require a suitable variable location instead.

Original paper, page 6