GATE Computer ScienceHardGATE CS (PYQ pattern)
void p(int x, int y) { x = x + 1; y = y + x; } is called as p(a, a) with a = 2. What is a after the call when the parameters are passed by value, by reference, and by value-result (copy-out in the order x then y), respectively?
- A. 2, 6 and 3
- B. 2, 6 and 5
- C. 2, 5 and 6
- D. 3, 6 and 5
Correct answer: B. 2, 6 and 5
By value: a is untouched, 2. By reference: x and y are both a: x = x + 1 makes a = 3, then y = y + x makes a = 3 + 3 = 6. By value-result: local x = y = 2; x becomes 3 and y = 2 + 3 = 5; copy-out writes a = 3 and then a = 5, so 5 (copying y first would give 3).
More Compiler Design questions
- How many distinct LR(0) items does the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id have (do not augment it…
- Dead-code elimination deletes every assignment whose target is not live immediately after it (live-variable analysis), and is repeated…
- Same function f(n) = 1 for n ≤ 2, else f(n − 1) + f(n − 2) + f(n − 3). Each activation record takes 28 bytes. What is the maximum stack…
- The SLR(1) table of S → i E t S Z | a; Z → e S | ε; E → b has one shift-reduce conflict (shift e versus reduce Z → ε), resolved as yacc…
- G: S → a A d | b B d | a B e | b A e; A → c; B → c is LR(1) but not LALR(1). Which of these changes, each made on its own, makes the…
- Sethi–Ullman labelling (a leaf is 1 if it is a left child and 0 if it is a right child, since a right operand may come from memory; an…