friend function

A friend function is a non-member function that helps to access private and protected data. This function is not part of the class but must be declared within the class so that it can access the private data. Generally, non-member functions cannot access private data, but there are situations when we need to do so. In this case, the friend function will be useful.