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 might the 'friend' keyword inside a class definition do?

  1. Declare another class that inherits all members

  2. Limit the class's visibility to certain functions

  3. Grant a function or another class special access to private members

  4. Declare a member function of the class

The correct answer is: Grant a function or another class special access to private members

The 'friend' keyword in a class definition allows a function or another class to have special access to private members of the class. This means that the 'friend' class or function can access and modify private data members, which are not accessible to other classes or functions. Option A is incorrect because the 'friend' keyword does not declare another class, it only grants access to the private members of a particular class. Option B is incorrect because the 'friend' keyword does not limit the class's visibility, it grants access. Option D is incorrect because declaring a member function would not require the use of the 'friend' keyword.