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.


What is the intended way to 'reset' or 'reinitialize' the 'oneChar' function with a new string?

  1. Directly modifying the static variable 's'

  2. Calling 'oneChar()' with the new string as an argument

  3. Destroying and recreating the function context

  4. None, it cannot be reinitialized manually

The correct answer is: Calling 'oneChar()' with the new string as an argument

When it comes to resetting or reinitializing a function, typically the best approach is to pass a new parameter or argument to the function. This is why option B, calling the function with a new string as an argument, is the intended way to reset the 'oneChar' function. Option A is incorrect because directly modifying the static variable 's' would only change the value of the variable, not the function itself. Option C, destroying and recreating the function context, is unnecessary and could lead to errors. Option D, stating that it cannot be reinitialized manually, is also incorrect as it is possible to pass a new parameter to the function and essentially reset it.