Friend functions and classes allow non-member functions or other classes to access the private and protected members of a class. A friend function is defined outside the class but has access to private members, and can be used when two classes need to access each other's private data. A class can declare another class as a friend, making all of its member functions friends. This allows them access to the private members of the other class. Friendship violates encapsulation but is useful when two classes are tightly coupled.