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 accurately describes the scope of the static variable `s` within the `oneChar` function?

  1. Local to the function

  2. Local to the module containing 'oneChar'

  3. Global across modules

  4. Accessible by other functions within the same file

The correct answer is: Local to the function

The static variable `s` is declared within the `oneChar` function, making it a local variable. This means that it can only be accessed within that specific function and not by other functions or modules. Options B and C are incorrect because they refer to the scope of the variable being limited to the module or across modules, which is not the case for a static variable declared within a function. Option D implies that other functions within the same file can access the variable, but this is not true for a static variable as it is only accessible within the function it is declared in. Therefore, option A is the correct answer as it accurately describes the scope of the static variable within the `oneChar` function.