GATE CS 2016 Set 1 — Question 46
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.MCQ+2 / -0.67MediumParameter PassingRuntime EnvironmentsCompiler DesignScoping (Static, Dynamic)Semantic Analysis
Compiler Design → Runtime Environments → Parameter Passing
Last updated
Question
What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?
a=3;
void n(x) {x = x * a; print(x);}
void m(y) {a = 1; a = y - a; n(a); print(a);}
void main() {m(a);}
Correct answer
(D) 4, 4
Solution
With dynamic scoping, a non-local name is resolved in the most recently active frame that declares it. With call by reference, a formal parameter is an alias of the actual variable.Inside
m, the statement a = 1 introduces m's own variable a (the global a is not overwritten), which is the reading under which the program is analysed.1.
main calls m(a): y is an alias of the global a, whose value is 3.2.In
m: local a = 1; then a = y - a = 3 - 1 = 2 (local a is now 2).3.
n(a) passes m's local a by reference, so x is an alias of it.4.In
n: a is not declared in n, so dynamic scoping finds the caller m's a (value 2). Then x = x * a = 2 \times 2 = 4; this writes 4 into m's a. print(x) prints 4.5.Back in
Output: m: print(a) prints m's a, which was changed through the reference to 4.4, 4.- (A) 6, 2 and (B) 6, 6 would need
a = 3to be used inn, i.e. static scoping to the globala. - (C) 4, 2 would need call by value, so the change to
xwould not reachm'sa.
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Runtime Environments
2026 Set 2 Q17In C runtime environment, which one of the following is stored in heap?2026 Set 2 Q19Consider the following three ANSI-C programs, P1, P2, and P3. P1 [code] P2 [code] **P3**…2026 Set 1 Q27Consider the following C statements: [figure] Which of the following options is/are correct?2026 Set 1 Q28Which of the following statements is/are true?2026 Set 2 Q35A lexical analyzer uses the following token definitions - - …