Friday, 29 June 2012

Concept Of Friend Function In C++


#include<iostream.h>
#include<conio.h>
 class frnd
 {
   int a,b,c;
   public:
   frnd(int x,int y)
   {
      a=x;
      b=y;
   }
 friend void sum(frnd k)
    {
     k.c=(k.a+k.b);
     cout<<"\nsum is : "<<k.c;
   }
 };
  
 void main()
 {
   clrscr();
   int a,b;
   cout<<"\nenter the value of 1st no : ";
   cin>>a;
   cout<<endl<<"enter the value of 2nd no. : ";
   cin>>b;
   frnd k(a,b);
   sum(k);
   getch();
 }

No comments:

Post a Comment