
C++ Friend Function Quiz
Authored by MARY T
Other

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is a friend function in C++?
A friend function in C++ is a function that can only be called from within the class.
A friend function in C++ is a function that can only access the public members of a class.
A friend function in C++ is a function that has access to the private and protected members of a class.
A friend function in C++ is a function that can be called from any other class except the one it is declared in.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the syntax of a friend function in C++?
friend return_type function_name(parameters);
friend return_type function_name;
friend function_name;
friend function_name(parameters);
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
How can a friend function access private members of a class in C++?
By being declared as a friend inside the class
By using the 'static' keyword
By using the 'protected' access specifier
By using the 'public' access specifier
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Can a friend function be a member of a class hierarchy in C++?
No
Yes
Sometimes
Only in certain cases
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is the difference between a friend function and a member function in C++?
A friend function is not a member of a class, while a member function is a member of a class.
A friend function can be called without an object, while a member function can only be called using an object.
A friend function is declared inside a class, while a member function is declared outside the class.
A friend function can only access public members of a class, while a member function can access both public and private members.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
True or False: A friend function can access protected members of a class in C++.
False
True
Only if the friend function is a member of the class
Only if the friend function is declared in the same file as the class
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
True or False: A friend function can be declared in the private section of a class in C++.
Only in derived classes
False
True
Only in public section
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?