Printing character Interger using friend function in C++


Example Program:

Here is the simple program for printing the character Interger using Friend Function in C++.

Source Code

#include<iostream>
using namespace std;
class XYZ
{
  private:
    char ch='A';
    int num = 11;
  public:
    friend class ABC;
};
class ABC
{
  public:
    void disp(XYZ obj)
    {
      cout<<obj.ch<<endl;
      cout<<obj.num<<endl;
    }
};
int main()
{
  ABC obj;
  XYZ obj2;
  obj.disp(obj2);
  return 0;
}
To download raw file Click Here

Output

A
11


Basic Programs


Flow Control

IF Statement Examples


Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes