+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

C++ Friend Interview Questions and Answers

What are the characteristics of friend functions?

Friend functions are not a part of the class and are external. This function is a “Friend” of a class. This is to say, it has special privileges to access to the class's private and protected members.

Explain the advantages of using friend classes. ?

There are situations when private data members need to be accessed and used by 2 classes simultaneously. In these kind of situations we can introduce friend functions which have an access to the private data members of both the classes. Friend functions need to be declared as ‘friend’ in both the classes. They need not be members of either of these classes.

What are friend classes?

The friend function is a ‘non member function’ of a class. It can access non public members of the class. A friend function is external to the class definition.

Which rule will not affect the friend function?

private and protected members of a class cannot be accessed from outside
Friend is used to access private and protected members of a class from outside the same class.

What is the syntax of friend function?

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

Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.