Which of the following storage classes have global visibility in C/C++ ?

2017

Which of the following storage classes have global visibility in C/C++ ?

  1. A.

    Auto

  2. B.

    Extern

  3. C.

    Static

  4. D.

    Register

Attempted by 956 students.

Show answer & explanation

Correct answer: B

Answer: Extern

Explanation: Variables or functions declared with extern have external linkage, which allows them to be referred to from other translation units (files) when properly declared and defined. Other storage classes do not provide this cross-translation-unit visibility.

  • Auto — automatic storage duration and block scope; local to the function or block and not globally visible.

  • Extern — external linkage: visible across translation units (global visibility) when declared/defined appropriately.

  • Static — at file scope gives internal linkage (visible only within the defining translation unit); at block scope gives static lifetime but the name remains local, so not globally visible across files.

  • Register — hint to store in a CPU register; has block scope and automatic storage, not global visibility. The address of a register variable cannot be taken.

Key takeaway: Only extern provides true global visibility across translation units.

Explore the full course: Mppsc Assistant Professor