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 output if func() is called 10 times and it increments a static integer initialized at 0?

  1. It will print numbers 0 to 9.

  2. It will print the number 10 ten times.

  3. It will print numbers 1 to 10.

  4. It will only print the number 1 ten times.

The correct answer is: It will print numbers 1 to 10.

If the static integer is initialized at 0, each time the function is called it will increment the value by 1. Therefore, the first call will print 1, the second call will print 2, and so on until the tenth call which will print 10. This is because the static integer will retain its value between function calls. Option A is incorrect because it will print numbers 1 to 10, not 0 to 9. Option B is incorrect because it will only print the number 10, not numbers 1 to 10. Option D is incorrect because it will only print the number 1, not numbers 1 to 10.