Skip to content
main-logo
  • +91 637-050-2482
  • santuitreturns@gmail.com
Menu
Menu
  • Home
  • Income Tax
    • Income From Salary
    • Profit or gain from Business/Profession.
    • Capital Gain
    • Income From Other Sources
    • 80C to 80U
    • TDS & TCS
    • ITR FORMS
  • International Taxation
    • Transfer Pricing
    • Non-Resident Taxation
    • Foreign Tax Credit (FTC)
    • Model Tax Convention
    • Base Erosion and Profit Shifting (BEPS)
  • GST
  • Accounting
  • MCQs
    • NEET
    • NEET QUIZ TEST
    • NEET PG MCQ’s
    • NEET PG QUIZ TEST
    • Civil Engineering
    • Mechanical Engineering MCQs
    • CHSL EXAM
      • Logical Reasoning
  • Others
    • Job Tips
  • CA Courses
    • CA Inter/IPCC

10+ TOP C++ MCQs on Friend Function

Posted on September 24, 2023

1. What is a friend function in C++?

A. A function which can access all the private, protected and public members of a class
B. A function which is not allowed to access any member of any class
C. A function which is allowed to access public and protected members of a class
D. A function which is allowed to access only public members of a class

View Answer

Answer: A

Explanation: 

Friend function in C++ is a function which can access all the private, protected and public members of a class.

2. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class Box
{
	int capacity;
    public:
	Box(int cap){
		capacity = cap;
	}
 
	friend void show();
};
 
void show()
{	
	Box b(10);
	cout<<"Value of capacity is: "<

A. Value of capacity is: 10
B. Value of capacity is: 100
C. Error
D. Segmentation fault

View Answer

Answer: A

Explanation:

 As show() is a friend function of class Box hence any object from this function can access the private member of the class Box.

3. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class Box
{
	int capacity;
    public:
	Box(int cap){
		capacity = cap;
	}
	friend void show();
};
 
void Box::show()
{	
	Box b(10);
	cout<<"Value of capacity is: "<

A. friend class1 Class2;
B. friend class;
C. friend class
D. friend class()

View Answer

Answer: A

Explanation:

 In option a, the class2 is the friend of class1 and it can access all the private and protected members of class1.

4. How many member functions are there in this C++ class excluding constructors and destructors?
class Box
{
	int capacity;
   public:
	void print();
	friend void show();
	bool compare();
	friend bool lost();
};

A. 1
B. 2
C. 3
D. 4

View Answer

Answer: B

Explanation:

 A friend functions are not members of any class. Hence this class has only 2 member functions.

5. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class B
{
	int b;
   public:
	B(int i){
		b = i;
	}
};
 
class C
{
	B b;
    public:
	C(int i){
		b = B(i);
	}
	friend void show();
};
 
void show()
{
	C c(10);
	cout<<"value of b is: "<

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault

View Answer

Answer: C

Explanation:

 There is two error in the program. First the program doesn’t have a default constructor for the class B which is used when the object of B is declared inside the class C. Second show() is friend function of class C therefore it can access only private member of class C, not B therefore when we are doing c.b.b here the last b is private member of class B which is not accessible.

6. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class B
{
	int b;
     public:
	B(){}
	B(int i){
		b = i;
	}
	int show(){
		return b;
	}
};
 
class C
{
	B b;
     public:
	C(int i){
		b = B(i);
	}
	friend void show();
};
 
void show()
{
	C c(10);
	cout<<"value of b is: "<

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault

View Answer

Answer: A

Explanation:

 The program follows correct syntax and semantics hence no errors.

7. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class B
{
	int b;
   public:
	B(){}
	B(int i){
		b = i;
	}
	int show(){
		return b;
	}
};
 
class C
{
	B b;
    public:
	C(int i){
		b = B(i);
	}
	friend void show(){
 
		C c(10);
		cout<<"value of b is: "<

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault

View Answer

Answer: C

Explanation:

 No function show() is defined in the scope of main() function.

8. What will be the output of the following C++ code?
#include 
#include 
using namespace std;
class B
{
	int b;
    public:
	B(){}
	B(int i){
		b = i;
	}
	int show(){
		return b;
	}
};
 
class C
{
	B b;
    public:
	C(int i){
		b = B(i);
	}
	friend void show(){
 
		C c(10);
		cout<<"value of b is: "<

A. value of b is: 10
B. value of b is: 12345435
C. error
D. segmentation fault

View Answer

Answer: C

Explanation:

 Friend functions are not members of any class therefore they should not be called using class objects.

9. Pick the correct statement.

A. Friend functions are in the scope of a class
B. Friend functions can be called using class objects
C. Friend functions can be invoked as a normal function
D. Friend functions can access only protected members not the private members

View Answer

Answer: C

Explanation:

 Friend functions are not in the scope of a class and hence cannot be called through a class object. A friend function can access all types of members of the class. They can be invoked as a normal function.

10. Which of the following is correct about friend functions?

A. Friend functions use the dot operator to access members of a class using class objects
B. Friend functions can be private or public
C. Friend cannot access the members of the class directly
D. All of the mentioned

View Answer

Answer: D

Explanation:

 Friend function can be declared either in private or public part of the class. A friend function cannot access the members of the class directly. They use the dot membership operator with a member name.

11. Which keyword is used to represent a friend function?

A. friend
B. Friend
C. friend_func
D. Friend_func

View Answer

Answer: A

Explanation:

 friend keyword is used to declare a friend function.

    You May Also Like...

  • 10+ TOP MCQs on C++ Basic Concepts
  • 10+ TOP C++ MCQs on OOPs Concept – 1
  • 10+ TOP C++ MCQs on OOPs Concept – 2
  • 10+ TOP MCQs on C++ Types
  • 10+ TOP C++ MCQs on Booleans
  • 10+ TOP C++ MCQs on Character Types
  • 10+ TOP C++ MCQs on Pointers into Arrays
  • 10+ TOP C++ MCQs on Constants

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Quick Links

  • Home
  • About Us
  • Privacy Policy
  • Terms of Use
  • Disclaimer
  • Contact Us

Categories

  • Income Tax
  • International Taxation
  • GST
  • MCQs
  • Others
  • CA Courses

Latest Posts

  • Five changes in ITR forms of FY 2024-25 (AY 2025-26)
  • Form 10-IEA: Option to Choose Old Tax Regime
  • What is Section 54EC of the Income Tax Act?
  • What is Section 54F of the Income Tax Act?
©2025 Online Solves. All rights Reserved | Developed by AlgoPage IT Solutions Pvt. Ltd.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT