GATE / CS ARCHIVE

SUBJECT COLLECTION

Programming in C · Scope, Lifetime & Storage Classes

18 questions, newest first

GATE CSE has asked 18 questions on Scope, Lifetime & Storage Classes (Programming in C) from 2000 to 2026, in 14 of the 46 papers; the most recent is in GATE CSE 2026 Set 2. In the last five years it carried 0.5 marks per 100-mark paper on average, against 0.7 since 2003. Since 2014 the questions have been 6 NAT and 4 MCQ. 3 groups of questions here are solved the same way; “One per method” keeps the newest of each.

Browse topics
1 mark · NAT
Report issue

C block scope and shadowing

Scope, Lifetime & Storage Classes

Question 34, GATE 2026: Function func(i,j) is called with i=9,j=10. If i<j, an inner block declares a new int i=0 and loops while that inner i<10, adding 2 to j and incrementing the inner i. After the block, printf("%d",i) executes. Determine the printed integer.
Tap to enlarge
Answer & solution

Official answer: 9

Step through it (42 steps)

Givens and goal

Function func(i,j) is called with i=9,j=10. If i<j, an inner block declares a new int i=0 and loops while that inner i<10, adding 2 to j and incrementing the inner i. After the block, printf("%d",i) executes. Determine the printed integer.

Approach

Track each distinct variable object and which declaration each occurrence of i refers to.

Step-by-step solution

1. The function receives its own parameter i with value 9 and parameter j with value 10. The initial comparison succeeds.
2. Inside the conditional block, a new local i is declared. It shadows the parameter i only within that block. The loop increments this inner variable from 0 to 10; it does not alter the parameter i.
3. The loop also increases the function-local j, which has no effect on the printed expression. When execution leaves the block, the inner i goes out of scope.
4. The print statement is outside the block. Its identifier i therefore refers to the parameter, still equal to 9. The output is 9, with no newline implied by the shown format string.

Common error: Shadowing creates a different object; it is not assignment to the outer object.

Scope trace

    Point                         Parameter i   Inner i   Parameter j
    Function entry                    9          absent        10
    Inner declaration                 9             0          10
    After ten loop iterations         9            10          30
    At printf                         9          absent        30

The table makes clear that reaching inner i=10 does not imply that printf prints 10. The condition uses the parameter before the inner declaration is reached, whereas the loop uses the inner object.

Original paper, page 24 · Answer key

1 mark · MCQ
Report issue

Locating dynamically allocated storage

Scope, Lifetime & Storage Classes

Question 17, GATE 2026: In the conventional C runtime model, which object is stored in the heap? A function-local static variable; B ordinary function-local integer array; C integer array allocated by malloc; D function return address.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Givens and goal

In the conventional C runtime model, which object is stored in the heap? A function-local static variable; B ordinary function-local integer array; C integer array allocated by malloc; D function return address.

Approach

Compare storage duration and allocation mechanism rather than source-code location.

Step-by-step solution

1. malloc requests dynamically allocated storage whose lifetime extends until it is released, typically by free. Conventional runtimes manage this storage in the heap. Thus C is the intended answer.
2. A local static variable exists for the program lifetime and conventionally occupies a static data region, despite its name having block scope. Scope does not determine storage duration.
3. An ordinary non-static local array has automatic storage duration and is conventionally placed in a stack frame. A return address is part of calling state, often on a stack or in an architecture-specific register.
4. A local pointer holding the malloc result can itself be in a stack frame while the array it points to is in the heap. The C standard specifies storage behavior, not physical regions literally named stack and heap; the answer uses the stated runtime convention.

Original paper, page 14 · Answer key

1 mark · MCQ
Report issue

Shadowing versus same-block redeclaration

Scope, Lifetime & Storage Classes

Question 19, GATE 2026: Each program includes stdio.h and has main returning 0. P1: file-scope int a=5; inside main, int a=7;. P2: inside one main block, int a=5; int a=7;. P3: inside one main block, int a=5; float a=7;. Which compiles without a required error? A only P1; B only P2; C only P3; D all.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Givens and goal

Each program includes stdio.h and has main returning 0. P1: file-scope int a=5; inside main, int a=7;. P2: inside one main block, int a=5; int a=7;. P3: inside one main block, int a=5; float a=7;. Which compiles without a required error? A only P1; B only P2; C only P3; D all.

Approach

Check whether declarations inhabit different scopes or attempt to define the same local identifier twice.

Step-by-step solution

1. P1 has an outer file-scope object and a distinct inner block-scope object. The inner a legally shadows the outer a inside main. The two definitions do not conflict because they are in different scopes.
2. P2 has two initialized definitions of the same ordinary automatic identifier in one block. It is not assignment to an existing object: the repeated type keyword introduces a second declaration/definition, which violates the constraints.
3. P3 also redeclares a in the same block, and additionally changes its type from int to float. This is not legal shadowing, because there is no nested inner block.
4. Only P1 is valid under the intended ANSI-C rules, so A. A compiler may issue a shadowing warning for P1, but an optional warning does not make the program invalid.

Original paper, page 16 · Answer key

1 mark · NAT
Report issue

Scope, Lifetime & Storage Classes

Question 35, GATE 2023: In C, funcp has static int x=1, then increments x and returns it. main declares separate int x,y, executes x=funcp(); y=funcp()+x; and prints x+y. What integer is printed?
Tap to enlarge
Answer & solution

Official answer: 7

The static local x in funcp persists across calls. Its first call increments 1 to 2 and returns 2, assigned to main’s x. The second increments the same static value 2 to 3; main’s y becomes 3+2=5. Therefore main prints x+y=2+5=7. The local static and main’s x are distinct objects.

Teaching detail. A static local has block scope but static storage duration: its initialization occurs once, and the stored value survives a return from the function. It is not reinitialized to 1 at each invocation. Track the function's private x separately from main's x to avoid accidental overwriting: after the first call they both happen to equal 2, but the second call changes only the static variable to 3. main's previously stored x remains 2 and participates in both subsequent arithmetic expressions.

Original paper, page 33 · Answer key

2 marks · NAT
Report issue

Scope, Lifetime & Storage Classes

Question 46, GATE 2020: Find fun2(5) on the first invocation of these C functions:
int fun1(int n) {
 static int i=0;
 if(n>0) { ++i; fun1(n-1); }
 return i;
}
int fun2(int n) {
 static int i=0;
 if(n>0) { i=i+fun1(n); fun2(n-1); }
 return i;
}
Tap to enlarge
Answer & solution

Official answer: 55

Step through it (18 steps)

Worked explanation

Use different names u and v in the trace for fun1’s and fun2’s separate static variables. Static initialization occurs once, not on every recursive call. The successive outer fun1 calls add 5,4,3,2,1 to u, making return values 5,9,12,14,15. At the corresponding fun2 entries, v becomes 5,14,26,40,55. The final fun2(0) returns 55 without changing it. When earlier calls unwind, they all return the same current static v=55; ignored recursive return values are not added again. This is why neither the triangular sum 15 nor the sum 5+4+3+2+1 is the final answer.

Derivation and answer

The two static variables named i belong to different functions and persist across calls. Starting from their initial zeros, fun1(5) increments its i five times and returns 5; subsequent fun1(4), fun1(3), fun1(2), fun1(1) return 9, 12, 14, 15 respectively. fun2 adds those five results into its own static i, so it returns 5+9+12+14+15=55. The recursive return values ignored inside fun1/fun2 do not undo updates to static storage. This assumes the displayed call is the first invocation, as intended.

Original paper, page 14 · Answer key

2 marks · MCQ
Report issue

Static state and for-loop evaluation order

Scope, Lifetime & Storage Classes

Question 27, GATE 2019: r() contains static int num=7 and returns num--. main executes for(r(); r(); r()) printf("%d",r()); then returns. Which displayed output is correct: A 41, B 52, C 63, D 630?
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Step through it (29 steps)

1. A static local variable is initialized once and keeps its value between calls. Post-decrement returns the old num and then reduces the stored value by one.
2. A for loop evaluates its initializer once, then repeatedly evaluates condition, body, and increment in that order. Calls in the initializer and increment still change num even though their returned values are discarded.
3. The initializer returns 7 and leaves num=6. The first condition returns 6, which is true, and leaves num=5. The body returns and prints 5, leaving num=4. The increment returns 4 and leaves num=3.
4. The second condition returns 3, so the body prints 2 and leaves num=1. The increment returns 1 and leaves num=0. The next condition returns 0, which is false, so there is no third body execution.
5. Only body calls print. No space or newline separates the two digits, so the displayed output is 52, option B. In particular, the zero used to stop the loop is never printed.

Original paper, page 9 · Answer key

2 marks · NAT
Report issue

Scope, Lifetime & Storage Classes

Question 55, GATE 2017: #include <stdio.h>
int total(int v) { static int count=0; while(v) { count+=v&1; v>>=1; } return count; }
void main() { static int x=0; int i=5; for(;i>0;i--) { x=x+total(i); } printf("%d\n",x); }
Find printed output.
Tap to enlarge
Answer & solution

Official answer: 23.0

Our answer: 23

1. Inside total, v&1 extracts the low bit and v>>=1 removes it. The loop counts set bits, but count is static: its value persists across different calls.

2. Arguments are 5,4,3,2,1, with binary forms 101,100,11,10,1 and popcounts 2,1,2,1,1. Therefore total returns cumulative counts 2,3,5,6,7, rather than the individual popcounts.

3. main adds each returned value to its own x: 2, then 5,10,16,23. The final output is 23. Resetting count on each call would wrongly give 7.

void main is a nonstandard hosted-C entry point; the exam assumes an implementation accepting it.

Original paper, page 24 · Answer key

2 marks · MCQ
Report issue

Scope, Lifetime & Storage Classes

Question 35, GATE 2016: Find the printed sequence for count(3), where:
void count(int n){static int d=1;printf("%d ",n);printf("%d ",d);d++;if(n>1)count(n−1);printf("%d ",d);}
A:3 1 2 2 1 3 4 4 4. B:3 1 2 1 1 1 2 2 2. C:3 1 2 2 1 3 4. D:3 1 2 1 1 1 2.
The printed main wrapper calls count(3); assume the usual printing declarations.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (7 steps)

The static d is shared across recursive calls. Entry pairs are(3, 1),(2, 2),(1, 3); after the third increment d=4. Each of the three returning frames then prints 4. The complete sequence is 3 1 2 2 1 3 4 4 4, A. The snippet assumes normal printf declarations and acceptance of its void-main wrapper.

There is one static storage cell for d, not one copy per recursion frame. Trace entry: count(3) prints 3,1 and increments to 2; count(2) prints 2,2 and increments to 3; count(1) prints 1,3 and increments to 4. The base call skips recursion but still executes its final print. Returning callers also execute that final print and see the same shared 4. No decrement or new initialization happens during unwinding, which explains all three trailing 4s.

Original paper, page 14 · Answer key

2 marks · NAT
Report issue

Scope, Lifetime & Storage Classes

Question 52, GATE 2015: A global int pointer A and global stkTop coexist with stkFunc’s static int size=0, stkTop=0. Opcode −1 sets size=val; opcode 0 pushes A[stkTop++]=val when stkTop<size; the default returns A[--stkTop] if nonempty, otherwise −1. main points A at B[20], sets global stkTop=−1, sets capacity 10, pushes 5 then 10, and prints stkFunc(1, 0)+stkFunc(1, 0). Find the output.
Tap to enlarge
Answer & solution

Official answer: 15

The function-local static stkTop starts at 0 and shadows the global stkTop, so assigning the global variable−1 does not affect the stack. After configuring size 10 and pushing 5 then 10, the two pops return 10 and 5 in whichever operand-evaluation order is chosen. Their sum is 15. Although the + operands have unspecified order, the two function executions are indeterminately sequenced rather than interleaving their bodies; this is not the direct unsequenced-increment case.

Track the function-local static top, not the global of the same name. Capacity initialization leaves the local top at 0. Pushing 5 writes B[0] and changes it to 1; pushing 10 writes B[1] and changes it to 2. The two calls then return 10 and 5, in whichever operand-call order is chosen. Their sum is 15. A function’s static local persists between calls, and lexical scope makes it hide the global stkTop, so setting that global to −1 does not underflow this stack.

Original paper, page 46 · Answer key

2 marks · NAT
Report issue

Scope, Lifetime & Storage Classes

Question 42, GATE 2015: Determine the output of this C program, using the standard function-call sequencing model:
#include <stdio.h>
int f1(void); int f2(void); int f3(void);
int x=10;
int main() { int x=1; x += f1()+f2()+f3()+f2(); printf("%d",x); return 0; }
int f1() { int x=25; x++; return x; }
int f2() { static int x=50; x++; return x; }
int f3() { x *= 10; return x; }
Tap to enlarge
Answer & solution

Official answer: 230

1. There are three distinct variables named x: global x, main’s automatic x, and f2’s persistent static x; f1 additionally creates its own automatic x on entry. Name lookup selects the nearest declaration, so f3 alone modifies the global. The two f2 returns may exchange evaluation order, but their sum stays 103.

2. Main’s local x starts 1. f1 returns 26 from its own automatic x; the two f2 calls return 51 and 52 from one static x in either order; f3 multiplies global 10 by 10 and returns 100. Sum1+26+51+52+100=230. Function executions are indeterminately sequenced, so unspecified operand order does not change the sum or cause overlapping unsequenced increments.

Original paper, page 67 · Answer key

2 marks · MCQ
Report issue

Static local storage and variable shadowing

Scope, Lifetime & Storage Classes

Question 48, GATE 2012: Common code (source-era C syntax retained):
int a,b,c=0;
void prtFun(void);
main() {
 static int a=1; /* Line 1 */
 prtFun(); a+=1; prtFun();
 printf(" \n %d %d ",a,b);
}
void prtFun(void) {
 static int a=2; /* Line 2 */
 int b=1;
 a+=++b;
 printf(" \n %d %d ",a,b);
}
What three output pairs are printed?
(A) (3,1);(4,1);(4,2) (B) (4,2);(6,1);(6,1) (C) (4,2);(6,2);(2,0) (D) (3,1);(5,2);(5,2).
Question 48, GATE 2012: Common code (source-era C syntax retained):
int a,b,c=0;
void prtFun(void);
main() {
 static int a=1; /* Line 1 */
 prtFun(); a+=1; prtFun();
 printf(" \n %d %d ",a,b);
}
void prtFun(void) {
 static int a=2; /* Line 2 */
 int b=1;
 a+=++b;
 printf(" \n %d %d ",a,b);
}
What three output pairs are printed?
(A) (3,1);(4,1);(4,2) (B) (4,2);(6,1);(6,1) (C) (4,2);(6,2);(2,0) (D) (3,1);(5,2);(5,2).
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Assume the snippet is meant as a storage-duration exercise with an appropriate printf declaration and a valid int main(void) supplied; the printed implicit-int main and omitted stdio declaration are not a portable modern-C complete program. The file-scope b has static storage and starts at 0. In prtFun, local b starts at 1 on each call and ++b makes it 2. Its static a starts at 2 once, then becomes 4 on the first call and 6 on the second, printing (4, 2) and (6, 2). The separate main-local a starts at 1 and is incremented to 2; main sees global b=0 and prints (2, 0). Hence C.

Check: There are three different a objects and two different b objects. The function-local a persists across calls but is not main’s a; function-local b shadows global b and never changes it. Keeping an object-by-object trace avoids incorrectly carrying local b back into main.

Original paper, page 13 · Answer key

2 marks · MCQ
Report issue

Automatic and register local lifetimes

Scope, Lifetime & Storage Classes

Question 49, GATE 2012: Common code (source-era C syntax retained):
int a,b,c=0;
void prtFun(void);
main() {
 static int a=1; /* Line 1 */
 prtFun(); a+=1; prtFun();
 printf(" \n %d %d ",a,b);
}
void prtFun(void) {
 static int a=2; /* Line 2 */
 int b=1;
 a+=++b;
 printf(" \n %d %d ",a,b);
}
Replace Line 1 by auto int a=1; and Line 2 by register int a=2;. What three pairs are printed?
(A) (3,1);(4,1);(4,2) (B) (4,2);(6,1);(6,1) (C) (4,2);(6,2);(2,0) (D) (4,2);(4,2);(2,0).
Question 49, GATE 2012: Common code (source-era C syntax retained):
int a,b,c=0;
void prtFun(void);
main() {
 static int a=1; /* Line 1 */
 prtFun(); a+=1; prtFun();
 printf(" \n %d %d ",a,b);
}
void prtFun(void) {
 static int a=2; /* Line 2 */
 int b=1;
 a+=++b;
 printf(" \n %d %d ",a,b);
}
Replace Line 1 by auto int a=1; and Line 2 by register int a=2;. What three pairs are printed?
(A) (3,1);(4,1);(4,2) (B) (4,2);(6,1);(6,1) (C) (4,2);(6,2);(2,0) (D) (4,2);(4,2);(2,0).
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Under the same intended valid-declarations assumptions as the preceding common-data question, changing main-local a to auto does not change its lifetime within this single invocation of main: it still becomes 2. Changing prtFun-local a to register gives it automatic storage duration, not persistent storage; each call initializes it to 2. Each call also initializes local b=1, increments b to 2, adds 2 to a, and prints (4, 2). Finally main prints its a=2 and the zero-initialized global b=0. The three output pairs are (4, 2), (4, 2), (2, 0), option D. register does not guarantee physical register allocation.

Check: Storage-class changes affect persistence, not lexical scope. Both modified declarations still shadow the same globals. The register local is recreated on every invocation, so it cannot retain the first call’s value 4 when the second call starts.

Original paper, page 13 · Answer key

2 marks · MCQ
Report issue

Recursive function with shared static state

Scope, Lifetime & Storage Classes

Question 42, GATE 2007: What is f(5) for the following C function?
int f(int n) {
    static int r=0;
    if(n<=0) return 1;
    if(n>3) { r=n; return f(n-2)+2; }
    return f(n-1)+r;
}
Options:
(A) 5
(B) 7
(C) 9
(D) 18
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step through it (11 steps)

1. Approach. The static r is one persistent shared object, not a fresh zero-initialized local for each recursive call. Record the single assignment r=5 before unwinding the recursion.

2. Derivation and interpretation. The static variable r is shared by all activations. In f(5), r becomes 5, and the return expression is f(3)+2. Calls f(3), f(2), and f(1) each recurse with n−1 and add the unchanged r=5. The base f(0)=1. Hence f(1)=6, f(2)=11, f(3)=16, and f(5)=18 (D). No smaller activation changes r, so operand evaluation order does not affect this particular call.

Original paper, page 10

2 marks · MCQ
Report issue

Recursion with a persistent static counter

Scope, Lifetime & Storage Classes

Question 31, GATE 2004: For the first invocation of this C function, what does f(1) return?
int f(int n) {
  static int i=1;
  if(n>=5) return n;
  n=n+i; i++;
  return f(n);
}
Options:
(A) 5
(B) 6
(C) 7
(D) 8
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step through it (6 steps)

1. On the first call, n=1,i=1; the update yields n=2,i=2. The next call yields n=4,i=3, then n=7,i=4.

2. Since7≥5, that call returns7 and the result propagates back, C. This assumes f(1) is the first call, since static i persists across calls.

3. Teaching check: Static storage is initialized once, not once per recursive activation. The entry states (n,i) are (1,1),(2,2),(4,3),(7,4). Replacing static i with an ordinary local initialized to 1 would produce a different trace and return 5.

Original paper, page 4

2 marks · MCQ
Report issue

Local shadowing and pointer update of a global

Scope, Lifetime & Storage Classes

Question 89, GATE 2003: Consider this C-style program (print emits its integer argument followed by a space):
int x;
void Q(int z) { z+=x; print(z); }
void P(int *y) {
  int x=*y+2;
  Q(x);
  *y=x-1;
  print(x);
}
main(void) { x=5; P(&x); print(x); }
What output is produced?
A. 12 7 6  B. 22 12 11  C. 14 6 6  D. 7 6 6
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. main sets the global x to 5 and passes its address, so y inside P points to that global object.
2. P declares a different, local x and initializes it to *y+2=5+2=7. Calling Q(x) copies 7 into Q's parameter z.
3. Q has no local x, so its x denotes the global, still 5. z becomes 7+5=12 and Q prints 12; this does not alter either x.
4. Back in P, *y=x−1 uses local x=7 on the right and writes 6 to the global through y. P prints its unchanged local 7.
5. main finally prints global x=6, producing 12 7 6, A. Passing the pointer allows the global update despite P's name shadowing.

Solution: main sets global x=5 and passes its address to P. P's local x becomes *y+2=7 and shadows the global only inside P. Q receives z=7; its unqualified x is the global 5, so z becomes 12 and Q prints 12. Returning to P, *y=x−1 writes 6 to the global, but P's local remains 7 and is printed. Finally main prints the global 6. The output is 12 7 6, A.

Original paper, page 13

2 marks · MCQ
Report issue

Persistent local state across function calls

Scope, Lifetime & Storage Classes

Question 2.20, GATE 2000: Function incr(i) has static int count=0, executes count=count+i and returns count. main loops i=0 through 4 inclusive, assigning j=incr(i). Find final j among 10,4,6,7.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step 1: A static local is initialized once and retains its value between calls. The successive arguments are 0,1,2,3,4.

Step 2: The retained count becomes 0,1,3,6,10. Each returned value is assigned to j, so the final assignment stores 10.

Thus A. Reinitializing count on every call would incorrectly yield 4; stopping the loop before i=4 would yield 6, but the printed condition is inclusive.

Original paper, page 6

Descriptive
Report issue

Trace static scope and value parameters

Scope, Lifetime & Storage Classes

Question 18(a), GATE 2000: Pseudo-Pascal: global x; Q(z) does z:=z+x; writeln(z). P(y) declares local x, does x:=y+2; Q(x); writeln(x). Main does x:=5; P(x); Q(x); writeln(x). Q and P are siblings declared in main. Find output under call-by-value and static scoping.
Question 18(a), GATE 2000: Pseudo-Pascal: global x; Q(z) does z:=z+x; writeln(z). P(y) declares local x, does x:=y+2; Q(x); writeln(x). Main does x:=5; P(x); Q(x); writeln(x). Q and P are siblings declared in main. Find output under call-by-value and static scoping.
Tap to enlarge
Answer & solution

Answer: 12 7 10 5 (no official key was published)

Main sets global x=5. P receives a separate value parameter y=5 and sets its local x=y+2=7. P calls Q(x), so Q receives a separate z=7. Static scoping resolves Q’s free x through its lexical declaration environment, main, not through the caller P: that x is the global 5. Therefore Q sets its own z=7+5=12 and prints 12. Because z was passed by value, P’s local x remains 7, so P next prints 7. Returning to main leaves global x=5. Main’s Q(x) receives z=5 and uses global x=5, so it prints 10; this changes only z. Finally main prints global x=5. The four outputs, one per writeln, are 12,7,10,5. Do not let P’s local x affect a statically scoped sibling procedure.

Original paper, page 9

Descriptive
Report issue

Trace dynamic scope and reference parameters

Scope, Lifetime & Storage Classes

Question 18(b), GATE 2000: Pseudo-Pascal: global x; Q(z) does z:=z+x; writeln(z). P(y) declares local x, does x:=y+2; Q(x); writeln(x). Main does x:=5; P(x); Q(x); writeln(x). Q and P are siblings declared in main. Find output under call-by-reference and dynamic scoping.
Question 18(b), GATE 2000: Pseudo-Pascal: global x; Q(z) does z:=z+x; writeln(z). P(y) declares local x, does x:=y+2; Q(x); writeln(x). Main does x:=5; P(x); Q(x); writeln(x). Q and P are siblings declared in main. Find output under call-by-reference and dynamic scoping.
Tap to enlarge
Answer & solution

Answer: 14 14 10 10 (no official key was published)

Main’s x starts at 5. In P(x), y aliases main’s x, but P also owns a distinct local x. It reads y=5 and assigns local x=7. Q(x) is then called with a reference to that local x, so z aliases P.x. Under dynamic scoping, Q’s free x resolves to the nearest active caller with an x, also P.x. The assignment z:=z+x therefore reads 7+7 and writes 14 into P.x. Q prints 14, and P’s next writeln(x) prints the same 14. Main’s global x is still 5 because neither assignment changed y or main.x. After P returns, main calls Q(x); now both reference parameter z and dynamically resolved x refer to main.x. Their old values are 5, so the assignment writes 10 into main.x. Q prints 10 and main’s final writeln(x) also prints 10. Aliasing and name resolution are separate steps: first identify each referenced storage cell, then evaluate the addition using its pre-assignment value.

Original paper, page 9