GATE Computer ScienceHardGATE CS (PYQ pattern)
With int i = 2 and the array A = [0, 3, 5, 7, 9, 11, 13] (indices from 0), the call f(A[i], i) is made to void f(p, q) { i = i + 1; p = p + 10; q = q * 2; } Parameters are passed by name (call by name: argument expressions are re-evaluated at each use). What are the values after the call returns?
- A. A[2..4] = 5, 7, 9; i = 3
- B. A[2..4] = 5, 17, 9; i = 6
- C. A[2..4] = 15, 7, 9; i = 6
- D. A[2..4] = 15, 7, 9; i = 4
Correct answer: B. A[2..4] = 5, 17, 9; i = 6
With call by name, p is the text A[i], re-evaluated after i = i + 1, so the element updated is A[3]; q is i itself so i ends at 6.
More Compiler Design questions
- How many states does the minimal complete DFA (dead state included) for the regular expression (ab | aba) over {a, b} have?
- For E → T R; R → + T R | − T R | ε; T → F P; P → ^ T | ε; F → ( E ) | id, compute FOLLOW of every non-terminal ( counts as a member). What…
- A basic block is converted to a DAG using value numbering, treating + and as commutative, reusing an existing node when the same operator…
- Minimal SSA form is built for 1: if p > 0 goto L2; 2: L1: x = x + 1; 3: if x > n goto L3; 4: L2: y = y + x; 5: if y < m goto L1; 6: L3…
- L is the set of strings over {a, b} that contain abab as a substring but do not end with abab. How many states does the minimal complete…
- An LR parser for E → T E′; E′ → + T E′ | ε; T → F T′; T′ → F T′ | ε; F → ( E ) | id parses "id + id id". How many reductions does it make…