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 happens if 'oneChar()' is called without argument before it is initialized with a call like 'oneChar(a)'?

  1. The function returns the first character of 'a'

  2. The function returns 0

  3. The function leads to a requirement failure

  4. The function initializes 's' with a default string

The correct answer is: The function leads to a requirement failure

If 'oneChar()' is called without any argument, it would lead to an error because there is no value to return. Without an argument, the function does not know what value to return as the first character. Therefore, option A and B are incorrect. Option D is also incorrect because the function does not initialize 's' with a default string, it only returns the first character of the given string. The correct choice is option C, as calling 'oneChar()' without any argument would not satisfy the requirement of providing a string to return the first character from.