Similar questions 5 more →
Scope, Lifetime & Storage Classes


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.