What is a Friend function in c++ language?

               What is C++?

C++ is an object oriented programming language.It is an extension to C programming. C++ was developed by Bjarne Stroustrup in 1979.

   C++ is a general purpose case sensitive, free - from programming language that support object oriented, procedural and generic programming. C++ is a middle level language,as it encapsulates both high and low level language features.

C++ support the object- oriented programming ,the four major pillar of object - oriented programming (OOPS) used in C++ are- 

1- Inheritance

2- Polymorphism

3- Encapsulation

4- Abstractions


      What is Function prototype?

A function prototype is a declaration that defines both : The arguments passed to the function and the type of value returned by the function. If we were to call function fool() which receives a float and an int as arguments and return a double value it's prototype would look like this .

   Double fool( float ,int);

 double fool(a,b)

int a; float b;

{

    // Same code 

}

//Prototype- like style 

double fool( int a, float b)

{

   //Same code 

}


          Friend Function


  • Friend Function is not a member function of a class  to  which it is a friend.
  • Friend Function is declared in the class with friend keywords.
  • It must be defined outside the class to which it is friend.
  • Friend Function can access any member of the class to which it is friend.
  • Friend Function can not access member of the class directly.
  • It has no caller object.
  • It should not be defined with membership label.

            Program Example 


Output 👉👉 5



-:Difference between C and C++ :- 

                    What is C :-
 
  • C was developed by Dennis Ritchie between the year 1969 and 1973 at AT & Bell Labs.
  • C does no support polymorphism, encapsulation and inheritance which means that C does not support object oriented programming.
  • C is a Subset of C++.
  • C contains 32 keywords.
  • For the development of code ,C supports procedural programming.
  • Data and functions are separated in C because it is a procedural programming language.
  • C does not support Information hiding.
  • Built - in data type is supported in C .
  • Function and operator overloading is not supported in C.
  • C is a function driven language.
  • Reference variables are not supported by C.
  • Virtual and Friend Function are not supported by C.
  • C does not support Inheritance.
  • C provide malloc() and calloc() function for dynamic memory allocation, and free() for memory de -allocation .

                   What is C++:-

  • C++ was developed by Bjarne Stroustrup in 1979.
  • C++ suppors polymorphism, encapsulation,and inheritance because it is an object oriented programming language.
  • C++ is a superset of C.
  • C++ contain 52 keywords.
  • C++ is known as hybrid language because c++ support both procedural and object oriented programming paradigm.
  • Data and functions are encapsulated together in form of an object in C++.
  • Data in hidden by the encapsulation to ensure that data structure and operators are used an intended.
  • Built in & user defined data type is supported in C++.
  • Function and operator overloading is supported in C++.
  • C++ is an object driven language.
  • Reference variables are supported by C++.
  • Virtual and Friend Function are  supported by C++.
  • C++ supported in C++.
  • C++ provide new operator for memory allocation and delete operator for memory de-allocation .
  • Exception handling is supported by C++.

Program Example

# include<iostream.h>

# include<conio.h>

Void main()

{

   Clrscr()

   Cout<<"welcome to c ++ programming";

 getch();

}


Thanks 👍😊





Comments

Post a Comment

Popular Posts