what is difference between friend function and inline function





What is difference between Friend function and Inline function ?


A friend function is used for accessing the non-public members of a class. A class can allow non-member functions and other classes to access its own private data, by making them friends. Thus, a friend function is an ordinary function or a member of another class. 


Inline functions are functions where the call is made to inline functions. The actual code then gets placed in the calling program. 
The inline function takes the format as a normal function but when it is compiled it is compiled as inline code. The function is placed separately as inline function, thus adding readability to the source program. When the program is compiled, the code present in function body is replaced in the place of function call.
Inline Function एक ऐसा Function होता है जिसे Call करने पर Program Control उस Called Function में नहीं जाताबल्कि Program Control जहां पर होता है वहीं पर Inline Function Expand हो जाता है और Program अपने Normal Flow में Execute होता रहता है। Inline Function को Execute करने के लिए Program Control को Jumping में किसी प्रकार का समय Waste नहीं करना पडता hai
Example of inline function:-
#include<iostream.h>
Inline float add (float a, float b)
{
return(a+b);
}
int main()
{
float a=5.4
float b=7.4
Cout<<add(a,b)
return 0;

} 

 Friend Function -C++ में friend function का उपयोग किया जा सकता है, Friend function की निम्नलिखित characterstics होती है।

friend function को class के object के जरिये access नही किया जा सकता है। इसको किसी भी normal function की तरह बिना object के invoke किया जा सकता है। किसी function को कितनी भी class में friend define किया जा सकता है। friend function को class के public या private किसी भी part में define किया जा सकता है।friend function को कितनी भी class में friend define किया जा सकता है।किसी भी function को friend function बनाने के लिए function के आगे Friend लिखा जाता है।Example- Friend void display(N);जहा N कोई object होगा।


Tausif

Hi! My name is TAUSIF AHMAD I have completed B.Tech in Computer Science from Maulana Azad National Urdu University Hyderabad. I am always ready to have new experiences meet new people and learn new things. 1. I am very interested in Frontend Development. 2. I love video editing and graphics designing. 3. I enjoy challenges that enables to grow. 4. I am part time Blogger.

1 Comments

Post a Comment
Previous Post Next Post