What Is Friend Function in C++ With Example In Hindi

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.

Kya Aap Jaante Hai?

Kisi bhi function ko friend function banaya jaa sakta hai. Kisi Bhi function ko Friend function Banane Ke Liye Us function ka “prototype” declaration class Ke Ander hi kar Diyaa Jata Hai.

Prototype Ke Starting me “Friend” keyword ka use Kiya Jata hai, & Jo Bhi Classes Friend Functions ka Use karti hai Unhe Friend Class kahi jati 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();

}

What Kind Of Program Is That???

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();

}

What Kind Of Program Is That???

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 this post.

Shubham

Hello Friends, I'm Shubham Gupta. Eduinhindi Ka founder, I just want to learn new things consistently that is why I created this blog. If you like my post share with your friends on the social media platform.

Recent Posts

What Is Polymorphism in oops | Compile & runtime polymorphism Example

What is a polymorphism in oops – Did you Want to Know What is Compile & runtime polymorphism With the…

8 months ago

Top 10 camera apps for android Jo apko download krna cahiye

Top 10 camera apps for android Jo apko download krna cahiye:-  aaj ki ye post hamare un friends ke liye…

12 months ago

Top 5 photo banane wala apps for android mobile downloads

'Top 5 photo banane wala apps for android mobile:- aj kis yeh post un selfie lovers ke liye hai jo…

12 months ago

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

What is inline Function in C++ in Hindi Language Puri Jankari:  Programming me function ka main objective memory Program ko small…

1 year ago

What is a database in Hindi Puri Jankari

What is a database in Hindi complete information: Hello friends, today we are going to learn about What is a database in…

1 year ago

What is Inheritance in C++ in Hindi Complete Guide

C++ ka most important feature 'Reusability'  hai. Iske Jariye ham Kisi existing class ko Kai types Se use Kr Sakte…

1 year ago