WAP to demonstrate the characteristics of friend function?
The characteristics of Friend Function is
Now, we are taking the example of the friend function:
#include <iostream> using namespace std; class Box { private: int length; public: Box() : length(0) {} friend int printLength(Box); }; int printLength(Box b) { b.length += 10; return b.length; } int main() { Box b; cout << "Length of box :" << printLength(b) << endl; return 0; }
The output of the above program is
Length of box :10
Click here to submit your answer.