Examveda

What does the 'static' keyword mean when used with a global variable in C++?

A. Scope limited to the file

B. Can't be modified

C. Retains its value between calls

D. Global scope

Answer: Option A

Solution (By Examveda Team)

Reason: In C++, when the 'static' keyword is used with a global variable, it limits the scope of that variable to the file in which it is declared.

Option A: Scope limited to the file is correct because a global variable declared as static can only be accessed within the file where it is defined, making it invisible to other files in the program.

Option B: Can't be modified is incorrect because the 'static' keyword does not make the variable constant or immutable. It can still be modified.

Option C: Retains its value between calls applies to local static variables, not global static variables. Global static variables are not related to function calls.

Option D: Global scope is incorrect because the 'static' keyword specifically restricts the scope of the variable to the file, contrary to the global scope.

Hence, the correct interpretation of 'static' for global variables is that it limits the scope to the file where the variable is declared.

Join The Discussion

Comments (1)

  1. Bhawna Wadhwa
    Bhawna Wadhwa:
    9 months ago

    Answer should be A.

    Plz check, May be I am wrong plz explain that answer of it is C

Related Questions on Introduction to C plus plus