A variable is defined as static int counter; at file scope in one translation unit. What does the static keyword change?
Correct answer
D. Its linkage becomes internal, so other translation units cannot refer to it by name
17 views
D. Its linkage becomes internal, so other translation units cannot refer to it by name
17 views
Internal linkage means the name is visible only inside its own translation unit, so a second file may define its own counter without a duplicate-symbol error. At file scope static does not alter storage duration, which remains static for the whole program. Inside a function the same keyword instead changes storage duration, which is why the two uses of static are a classic trap.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.