What Is Friend Function in C++ With Example In Hindi:- Hello Friends Mera Naam Shubham Hai, & I am Back With QA Series Of C++ And Aj ka Topic hai What is Friend Function in C++ in Hindi.

 

What Is Friend Function in c++ in Hindi

As we know private member functions ko Class ke Bahaar Access Nahi kiya Jaa Sakta Hai. If we have more then one class Aur ham kisi Common function ko Access Karna Cahte hai to is Tarah ki situation me ek Special type ke Function ko Create kiyaa jata hai. Jise Friend Function Kahte hai.

Kisi bhi function ko Friend function Banane ke Liye Us function ka “prototype” declaration class Ke Ander hi karDiyaa Jata Hai.

Prototype Ke Starting me “Friend” keyword ka use kiya jata hai, & Jo bhi Clesses Friend Functions ka Use karti hai Unhe Friend Class kaha jata hai.

Important Points in Friend function in Hindi

  1. Friend Function Kisi bhi Class ka member Nahi hota. Isliye ise Non-Member Function Kahte hai.
  2. Friend Function Kisi Bhi private function ko class ke bahar use karne ki Facilities provide karwata Hai.
  3. Class ke member Dusre Class ke members se separate rahte hai.

Friend Function in Hindi Example

#include<iostream.h>

#include<conio.h>

class bank

{private:

int ano;

char name[20];

int bal;  

public:

void get()

{ cout<<“Enter account no= “;      cin>>aon;

cout<<“Enter Name= “;    cin>>name;

cout<<“Enter Balance= “;     cin>>bal;

}    void show()

{  cout<<ano<<“\t”<<name<<“\t”<<bal<<“\n”;

friend bank change (bank);

};

bank change (bank x)

{ x.bal=0;

return x;

}

void main()

{ clrscr();

bank b;

b.get();

b = change(b);

b.show();

getch();

}

Is program Me Hamne Sabse Pahle Ek Bank Name ki Class Create ki Fir Usme Bank ‘b’ Ke object Se get(); function Ko call Karke sare Variables me values Assign Karli, Iske baad hamne Class Ke Bahar Ek Friend Function change() ka use Karke Usme  ‘bal’ Variable ki value 0 Kar di. iske Baad Hamne object b ke jariye show() function ki calling ki, Aur Result Screen me Print krwa Diya.

 

Friend Function in Hindi Second example

#include<iostream.h>

#include<conio.h>

class second;

class first

{private:

int a;

public:

void get();

{cin<<“enter Value Of a:= “; cout>>a;

}  

friend int sum (first,second);

};

class second

{private:

int b;

public:

void get();

{ cout<<“enter Value Of b:= “; cin>>b;

} friend in sum (first,second);

};

int sum (first,second)

{ int n = f.a + s.b;

return n;

}

void main()

{ clrscr();

first f; second s;

f.get(); s.get();

int t = sum(f,s);

cout<<“Totle =”<<t;

getch();

}

is C++ ke Program Me Hamne Sabse Pahle 2 Classes Create ki hui hai jinke naam ‘first‘ ‘second‘ iske baad dono ke object ke jariye a and b me value assign Kar Diya.

value assign karne ke baad ek Sum Function create kiya jisko class first and second me friend define Kar Diya. fir ek integer object “t” ke Jariye sum function ki Calling ki Aur Usme Argument ke roop me (first & Second Class) Ke object ko bhej diya Aur fir hamne ‘t’ Ko print karwa Diya.

To Know More Information About Friend Function Watch This Tutorial

Video Credit: easytuts4you

Related Post

What is Copy Constructor in C++ Explain With Example in Hindi

What is inheritance in c++ in Hindi Complete Guide

What is inline Function in C++ in Hindi Language Puri Jankari

Thankyou For Reading This Post, If You Like it Share With Your Friends On Social Media. Comment if you have any question regarding to this post.

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.