GATE Computer ScienceVery hardGATE CS (PYQ pattern)
int i = 1; int A[0..2] = {5, 6, 7}; void f(x, y) { x = x + 1; y = 10; } The call f(i, A[i]) uses copy-in/copy-out (value-result), copying back x first, then y. What is A after the call if the copy-out addresses are computed at call time, and if they are recomputed at return time?
- A. {5, 10, 7} and {5, 10, 7}
- B. {5, 6, 10} and {5, 10, 7}
- C. {5, 10, 7} and {5, 6, 10}
- D. {5, 6, 7} and {5, 6, 10}
Correct answer: C. {5, 10, 7} and {5, 6, 10}
Copy-in: x = 1, y = A[1] = 6; the body makes x = 2, y = 10. Copy-out writes i = 2 first. If A[i]'s address was fixed at the call it is A[1]: A = {5, 10, 7}. If it is recomputed at return, i is already 2, so y goes to A[2]: A = {5, 6, 10}, and A[1] keeps 6.
More Compiler Design questions
- For G: S → x S y | x y | S S, which statements are true? I. G is ambiguous. II. The canonical LR(1) table has more multiply-defined cells…
- A lexer uses longest match, breaking ties in favour of the rule listed first, with rules: KW = if | then; ID = [a-z][a-z0-9]; NUM =…
- G: S → id | id [ E ] | id ( E ); E → id. G′ is obtained from G by left factoring S. Which statements are true? I. G is LL(1). II. G′ is…
- Construct the SLR(1) parsing table of S → a B | b A; A → a | a S | b A A; B → b | b S | a B B (augmented). In how many states of the…
- An NFA over {a, b} has states 0 to 4, start state 0, and these moves (a missing move means no transition): δ(0,a)={1,2}; δ(0,b)={0,1,2}…
- Build the SLR(1) table for S → ( L ) | x; L → S | L , S (augmented with S′ → S). The ACTION part has a column for each of (, ), x, , and…