GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Consider this pseudo-code (arrays are 1-based): i = 1; a = [5, 6, 7]; procedure P(x, y) { x = x + 1; y = y * 2; } P(i, a[i]); print(i, a[1], a[2]); With call by name (the actual argument expression is re-evaluated at every use), the printed values are:
- A. 2 12 7
- B. 1 6 7
- C. 2 6 14
- D. 2 6 7
Correct answer: C. 2 6 14
Under call by name, x = x + 1 changes i to 2. The statement y = y * 2 then re-evaluates a[i], which is now a[2], so a[2] becomes 14 and a[1] stays 6. Call by reference would bind y to a[1] at call time and print 2 12 7.
More Compiler Design questions
- A C-like scanner uses maximal munch with these tokens: identifiers (letters and digits, starting with a letter) and the operators ++…
- A generated scanner for the token set { a, abcd, b, c, d } always returns the longest accepting prefix, and if the DFA reaches the dead…
- A scanner generator is given the rules, in this order: (1) if → IF; (2) [a-z][a-z0-9] → ID; (3) [0-9]+ → NUM. It uses the longest match…
- The Thompson construction (Aho–Sethi–Ullman style: a symbol gets 2 states; union and star each add a new start and a new final state…
- In the Thompson NFA for (a|b), each symbol machine has 2 states and 1 non-ε edge; union and star add a new start and final state with 4…
- A floating-point literal is defined over the symbols d (digit), '.', e and s (sign) as d⁺ ( . d⁺ )? ( e s? d⁺ )?. How many states does the…