The main function creates a Rectangle object and then calls the area function with the object as its argument. Because the area function is a friend function of the Rectangle class, it has access to the private members of the object and can calculate the area of the rectangle.
By using friend functions in C++, you can provide access to the private and protected members of a class to functions that are not members of the class, while still maintaining the encapsulation of the class's data.