1. Home
  2. Computer Science MCQs
  3. C Programming
  4. A variable is defined as static int counter; at file scope…

Added 30 Nov -0001

A variable is defined as static int counter; at file scope in one translation unit. What does the static keyword change?

  1. Its storage duration becomes automatic, so it is created afresh on each function call
  2. Its initialisation is deferred until the variable is first used inside the unit
  3. Its value is placed in read-only memory, so only the defining unit can modify it
  4. Its linkage becomes internal, so other translation units cannot refer to it by name Correct answer

Correct answer

D. Its linkage becomes internal, so other translation units cannot refer to it by name

17 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs