Mastering C++: A Comprehensive Quiz Based on 'Thinking in C++'

Disable ads (and more) with a membership for a one time $2.99 payment

Test your C++ skills with our quiz based on Bruce Eckel's 'Thinking in C++'. Dive into object-oriented programming, advanced topics, and fundamentals. Perfect for learners and experts alike. Assess your knowledge and become a C++ master!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which of the following best describes the visibility of a static variable declared inside a function?

  1. Global to the entire program

  2. Local to the function in which it is declared

  3. Local to the file containing the function

  4. Global to all functions within its file

The correct answer is: Local to the function in which it is declared

Static variables declared inside a function are only accessible within that specific function. This means that they are local to the function, as they cannot be accessed or modified by other functions or variables outside of that function's scope. This makes options A, C, and D incorrect as they describe static variables as being global or local to the file, rather than the function itself. Option B is the best choice as it accurately explains the visibility of a static variable within a function.