C++ Question Answer’s In Hindi : Friend Function in c++ With Example

Friend Function in c++ in hindi Explain With Example:- Hello Friend’s, This is shubham And i am Back With this QA Series Of C++. In this Series you Will Gets Most important Question And Answers’s For Your Computer Science Exam. Show Let’s Get Started… As You Can See in The Title Here is our Fifth Question.

Friend Function in c++ hindi

What is Friend Function in c++ in hindi

Q.5.- Friend Function in c++ in hindi With example

As we know private member functions ko Class ke bahaar Access nahi kiyaa jaa sakta. If we have more then one class aur ham kisi common function ko Access karna Cahte hai tb is tarah ki situation me ek Special type ke Function ko Create kiyaa jata hai. Usee Friend Function kahte hai.

kisi bhi function ko Friend function banane ke liye us function ka “prototype” declaration class ke ander hi kar diya 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. Friend function in C++ hindi important Points:

  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 kiya 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 kiye ‘bal’ Variable ki value 0 kar di. iske Baad Hamne object b ke jariye show function ki calling ki.. Friend function in hindi full information.

Friend Function in C++ ko Second example Ke jariye Aur Ache se Samjha Jaa sakta hai.

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 ‘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. and fir t Ko print karwa Diya. “Friend Function in hindi”

 

To guys Apko Meri Ye Post “C++ Question Answer’s In Hindi : Friend Function in c++ hindi With Example”  kaisi Lagi Hame Jarur Bataye Apne Comments Ke madhyam Se.. Aur Koi Question Ho To Aap Hamse Puch Sakte Hai.. Post Achi Lagi To Share Karna Na Bhule..

Best Shubham.

Contact me On Fb. Shubham Gupta

 

Friend Function in c++ hindi!!!!

Friend Function Kya hai!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Show Buttons
Hide Buttons