GATE Computer ScienceVery hardGATE CSE · NIELIT
In a language with Algol-style call by name, int i = 1 and A = [10, 20, 30] (1-indexed) are global, and procedure P(p, q) { i = i + 1; p = p + q; } is called as P(A[i], i). What is the array after the call under call by name, call by reference, and call by value respectively?
- A. [10,22,30], [12,20,30], [10,20,30]
- B. [10,22,30], [10,22,30], [10,20,30]
- C. [12,20,30], [10,22,30], [10,20,30]
- D. [10,22,30], [12,20,30], [12,20,30]
Correct answer: A. [10,22,30], [12,20,30], [10,20,30]
By name, p is re-evaluated as A[i] with i = 2, so A[2] = 20 + 2 = 22. By reference, p is bound to A[1] and q to i, so A[1] = 10 + 2 = 12. By value, only copies change and A is unchanged.
More Compiler Design questions
- Indirect left recursion is removed from S → A a | b; A → A c | S d | ε by ordering the non-terminals S, A, substituting S into A's rules…
- In S → A B C | C a; A → a A | ε; B → b B | A c | ε; C → d | B e, how many symbols (including ) does FOLLOW(B) contain?
- How many of these four grammars are LL(1)? (1) S → a S b | ε; (2) S → A B; A → a | ε; B → a | b; (3) S → a A | b; A → S c | ε; (4) S → S a…
- Statements: 1: a = 1; 2: b = 2; 3: c = a + b; 4: d = c 2; 5: if d > 10 goto 8; 6: e = a + d; 7: goto 9; 8: e = b + 1; 9: print e. Which…
- A C lexer applies the maximal-munch rule (always take the longest possible token). How many tokens does it produce for the input…
- How many basic blocks does this three-address code contain? 1: i = 0; 2: s = 0; 3: if i >= n goto 9; 4: t = a[i]; 5: if t < 0 goto 7; 6: s…