SlideShare a Scribd company logo
FUNCTION DIFFERENT
TYPES OF FUNTION
Presented By:-VISHAL SINGH
(Y18271026)
M.C.A 2nd sem
FUNTION IN C++
• A Function is a group of statements that together perform a
specific task. Every C++ program has at least one function,
which is main().
• Why use function ?
• Function are used to divide a large code into a module.
• Due to this we can easily debug and maintain the code.
COMPONENTS OF FUNCTION
• A function usually has three components.
• They are:
• Function prototype/declaration
• Function definition
• Function call
1-Function Prototype/Declaration
• Function declaration informs the compiler about the function’s name, type
and number of argument it receives and type of value it returns.
• Syntax for function declaration
• For example,
// function name = display, receives a character as argument and returns
nothing
void display(char);
// function name=sum, reveives two integers as argument and returns and
integer
int sum(int,int);
return_type function_name(parameter);
2-FUNCTION DEFINITION
Defining of function is nothing but give body of function that
means write logic inside function body.
return_type function_name(parameter)
{
//function body;
}
3-FUNCTION CALL
• Function call statement calls the function by
matching its name and arguments. A function call
can be made by using function name and
providing the required parameters.
• Syntax for function call
function_name();
or
variable=function_name(argument);
EXAMPLE OF FUNCTION
void sum(); // declaring a function
a=10,b=20,c;
void sum() // defining function
{
c=a+b;
cout<<“sum:”<<c;
}
int main()
{
sum(); // calling function
}
Sum: 30
TYPE OF FUNCTION
There are different type of function in C++
Language:-
• Library function or pre-define function
• User defined function.
• Overloading function.
• Inline function.
• Friend function.
• Static function.
• Constructor function.
• Destructor function.
• Virtual function.
LIBRARY FUNCTION
• Library function are those which are predefined in
C++ compiler.
• The implementation part of pre-defined functions is
available in library files that are .lib/.obj files. .lib or
.obj files are contained pre-compiled code.
• printf(), scanf(), clrscr(), pow() etc. are pre-defined
functions.
USER DEFINED FUNTION
• These functions are created by programmer according to
their requirement.
• For example:-suppose you want to create a function for add
two number then you create a function with name sum()
this type of function is called user defined function.
OVERLOADING FUNCTION
• Whenever same method name is exiting multiple times in
the same class with different number of parameter or
different order of parameters or different types of
parameters is known as function overloading.
“Doing work in different way is called overloading”.
Different way to overload the method:-
1. By Changing number of arguments or parameters
2. By Changing the data type
By Changing Number of parameter
By Changing the Data type
INLINE FUNCTION IN C++
• An inline function is a combination of macro
& function. At the time of declaration or
definition, function name is preceded by word
inline.
• Function calls involve execution-time
overhead.
• Inline functions to help reduce function call
overhead, especially for small functions.
Example of Inline function in C++
inline void show()
{
cout<<“Hello World”;
}
int main()
{
show(); // Call it like a normal function
}
Inline
function
Hello World
FRIEND FUNCTION IN C++
• A Friend function is a non-member function of the class that has
been granted access to all private members of the class.
• We simply declare the function within the class by a prefixing its
declaration with keyword friend.
• Function definition must not use keyword friend.
• Definition of friend function is specified outside the class body
and is not treated as a part of the class.
• The major difference b/w member function and friend function is
that the member function is accessed through the object while
friend function requires object to be passed as parameter.
FRIEND FUNCTION IN C++
Syntax:
class ABC
{
……………
public:
friend void xyz(object of class);
};
STATIC FUNTION IN C++
• We can define class members static using static keyword.
• When we declare a member of a class as static no matter
how many objects of the class are created.
• There is only one copy of the static member.
• A static member is shared by all objects of the class.
• All static data is initialized to zero when the first object is
created, if no other initialization is present.
• Static member function called by :: inplace of .
Operator.
STATIC FUNTION EXAMPLE
VIRTUAL FUNTION IN C++
• A virtual function a member function which is declared
within base class and is re-defined (Overriden) by derived
class.
• They are mainly used to achieve Runtime polymorphism
• Functions are declared with a virtual keyword in base
class.
• The resolving of function call is done at Run-time.
EXAMPLE OF VIRTUAL FUNTION
Class A
{ public:
virtual void show(){
cout<<“Hello base classn”;}
};class B : public A {
public:
void show() {
cout<<“Hello derive class”;
}
};
Function different types of funtion
Ad

More Related Content

What's hot (20)

Operator overloading
Operator overloadingOperator overloading
Operator overloading
Ramish Suleman
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
operator overloading in C++
operator overloading in C++operator overloading in C++
operator overloading in C++
baabtra.com - No. 1 supplier of quality freshers
 
C++ overloading
C++ overloadingC++ overloading
C++ overloading
sanya6900
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
ArunaDevi63
 
Bca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloadingBca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloading
Rai University
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
rajshreemuthiah
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversions
Amogh Kalyanshetti
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Function overloading
Function overloadingFunction overloading
Function overloading
Ashish Kelwa
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
ramya marichamy
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Garima Singh Makhija
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Maaz Hasan
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
Docent Education
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
C++ overloading
C++ overloadingC++ overloading
C++ overloading
sanya6900
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
Inline function
Inline functionInline function
Inline function
Tech_MX
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
Vraj Patel
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
ArunaDevi63
 
Bca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloadingBca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloading
Rai University
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
rajshreemuthiah
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversions
Amogh Kalyanshetti
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Function overloading
Function overloadingFunction overloading
Function overloading
Ashish Kelwa
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Nilesh Dalvi
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Maaz Hasan
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
gourav kottawar
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 

Similar to Function different types of funtion (20)

Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
Kumar
 
Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1
NageshPratapSingh2
 
c++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskkc++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
syedabbas594247
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
Ashim Lamichhane
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
Amresh Raj
 
Lecture 4- Javascript Function presentation
Lecture 4- Javascript Function presentationLecture 4- Javascript Function presentation
Lecture 4- Javascript Function presentation
GomathiUdai
 
3-Python Functions.pdf in simple.........
3-Python Functions.pdf in simple.........3-Python Functions.pdf in simple.........
3-Python Functions.pdf in simple.........
mxdsnaps
 
Functions and structure in programming c
Functions and structure in programming cFunctions and structure in programming c
Functions and structure in programming c
dalalbhargavi19
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
Bharath904863
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversion
Hashni T
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).pptchapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Functions, classes & objects in c++
Functions, classes & objects in c++Functions, classes & objects in c++
Functions, classes & objects in c++
ThamizhselviKrishnam
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
Kumar
 
Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1Object Oriented Programming using C++ Unit 1
Object Oriented Programming using C++ Unit 1
NageshPratapSingh2
 
c++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskkc++.pptxwjwjsijsnsksomammaoansnksooskskk
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
syedabbas594247
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
Amresh Raj
 
Lecture 4- Javascript Function presentation
Lecture 4- Javascript Function presentationLecture 4- Javascript Function presentation
Lecture 4- Javascript Function presentation
GomathiUdai
 
3-Python Functions.pdf in simple.........
3-Python Functions.pdf in simple.........3-Python Functions.pdf in simple.........
3-Python Functions.pdf in simple.........
mxdsnaps
 
Functions and structure in programming c
Functions and structure in programming cFunctions and structure in programming c
Functions and structure in programming c
dalalbhargavi19
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
Sowmya Jyothi
 
C++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversionC++ - Constructors,Destructors, Operator overloading and Type conversion
C++ - Constructors,Destructors, Operator overloading and Type conversion
Hashni T
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).pptchapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
zueZ3
 
Ad

Recently uploaded (14)

GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdfGiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
Giacomo Vacca
 
35 Must-Have WordPress Plugins to Power Your Website in 2025
35 Must-Have WordPress Plugins to Power Your Website in 202535 Must-Have WordPress Plugins to Power Your Website in 2025
35 Must-Have WordPress Plugins to Power Your Website in 2025
steve198109
 
introduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.pptintroduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.ppt
SherifElGohary7
 
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness GuideThe Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
russellpeter1995
 
30 Best WooCommerce Plugins to Boost Your Online Store in 2025
30 Best WooCommerce Plugins to Boost Your Online Store in 202530 Best WooCommerce Plugins to Boost Your Online Store in 2025
30 Best WooCommerce Plugins to Boost Your Online Store in 2025
steve198109
 
Save TikTok Video Without Watermark - Tikcd
Save TikTok Video Without Watermark - TikcdSave TikTok Video Without Watermark - Tikcd
Save TikTok Video Without Watermark - Tikcd
Tikcd
 
Paper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdfPaper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdf
Steven McGee
 
Big_fat_report_from Kaspersky_IR_Report_2024.pdf
Big_fat_report_from Kaspersky_IR_Report_2024.pdfBig_fat_report_from Kaspersky_IR_Report_2024.pdf
Big_fat_report_from Kaspersky_IR_Report_2024.pdf
avreyjeyson
 
an overview of information systems .ppt
an overview of  information systems .pptan overview of  information systems .ppt
an overview of information systems .ppt
DominicWaweru
 
plataforma virtual E learning y sus características.pdf
plataforma virtual E learning y sus características.pdfplataforma virtual E learning y sus características.pdf
plataforma virtual E learning y sus características.pdf
valdiviesovaleriamis
 
TAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIA
TAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIATAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIA
TAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIA
TAIPAN 99
 
ProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptxProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptx
OlenaKotovska
 
Java developer-friendly frontends: Build UIs without the JavaScript hassle- JCON
Java developer-friendly frontends: Build UIs without the JavaScript hassle- JCONJava developer-friendly frontends: Build UIs without the JavaScript hassle- JCON
Java developer-friendly frontends: Build UIs without the JavaScript hassle- JCON
Jago de Vreede
 
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
werhkr1
 
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdfGiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
GiacomoVacca - WebRTC - troubleshooting media negotiation.pdf
Giacomo Vacca
 
35 Must-Have WordPress Plugins to Power Your Website in 2025
35 Must-Have WordPress Plugins to Power Your Website in 202535 Must-Have WordPress Plugins to Power Your Website in 2025
35 Must-Have WordPress Plugins to Power Your Website in 2025
steve198109
 
introduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.pptintroduction to html and cssIntroHTML.ppt
introduction to html and cssIntroHTML.ppt
SherifElGohary7
 
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness GuideThe Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
The Hidden Risks of Hiring Hackers to Change Grades: An Awareness Guide
russellpeter1995
 
30 Best WooCommerce Plugins to Boost Your Online Store in 2025
30 Best WooCommerce Plugins to Boost Your Online Store in 202530 Best WooCommerce Plugins to Boost Your Online Store in 2025
30 Best WooCommerce Plugins to Boost Your Online Store in 2025
steve198109
 
Save TikTok Video Without Watermark - Tikcd
Save TikTok Video Without Watermark - TikcdSave TikTok Video Without Watermark - Tikcd
Save TikTok Video Without Watermark - Tikcd
Tikcd
 
Paper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdfPaper: World Game (s) Great Redesign.pdf
Paper: World Game (s) Great Redesign.pdf
Steven McGee
 
Big_fat_report_from Kaspersky_IR_Report_2024.pdf
Big_fat_report_from Kaspersky_IR_Report_2024.pdfBig_fat_report_from Kaspersky_IR_Report_2024.pdf
Big_fat_report_from Kaspersky_IR_Report_2024.pdf
avreyjeyson
 
an overview of information systems .ppt
an overview of  information systems .pptan overview of  information systems .ppt
an overview of information systems .ppt
DominicWaweru
 
plataforma virtual E learning y sus características.pdf
plataforma virtual E learning y sus características.pdfplataforma virtual E learning y sus características.pdf
plataforma virtual E learning y sus características.pdf
valdiviesovaleriamis
 
TAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIA
TAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIATAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIA
TAIPAN99 PUSAT GAME AMAN DAN TERGACOR SE ASIA
TAIPAN 99
 
ProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptxProjectArtificial Intelligence Good or Evil.pptx
ProjectArtificial Intelligence Good or Evil.pptx
OlenaKotovska
 
Java developer-friendly frontends: Build UIs without the JavaScript hassle- JCON
Java developer-friendly frontends: Build UIs without the JavaScript hassle- JCONJava developer-friendly frontends: Build UIs without the JavaScript hassle- JCON
Java developer-friendly frontends: Build UIs without the JavaScript hassle- JCON
Jago de Vreede
 
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
DEF CON 25 - Whitney-Merrill-and-Terrell-McSweeny-Tick-Tick-Boom-Tech-and-the...
werhkr1
 
Ad

Function different types of funtion

  • 1. FUNCTION DIFFERENT TYPES OF FUNTION Presented By:-VISHAL SINGH (Y18271026) M.C.A 2nd sem
  • 2. FUNTION IN C++ • A Function is a group of statements that together perform a specific task. Every C++ program has at least one function, which is main(). • Why use function ? • Function are used to divide a large code into a module. • Due to this we can easily debug and maintain the code.
  • 3. COMPONENTS OF FUNCTION • A function usually has three components. • They are: • Function prototype/declaration • Function definition • Function call
  • 4. 1-Function Prototype/Declaration • Function declaration informs the compiler about the function’s name, type and number of argument it receives and type of value it returns. • Syntax for function declaration • For example, // function name = display, receives a character as argument and returns nothing void display(char); // function name=sum, reveives two integers as argument and returns and integer int sum(int,int); return_type function_name(parameter);
  • 5. 2-FUNCTION DEFINITION Defining of function is nothing but give body of function that means write logic inside function body. return_type function_name(parameter) { //function body; }
  • 6. 3-FUNCTION CALL • Function call statement calls the function by matching its name and arguments. A function call can be made by using function name and providing the required parameters. • Syntax for function call function_name(); or variable=function_name(argument);
  • 7. EXAMPLE OF FUNCTION void sum(); // declaring a function a=10,b=20,c; void sum() // defining function { c=a+b; cout<<“sum:”<<c; } int main() { sum(); // calling function } Sum: 30
  • 8. TYPE OF FUNCTION There are different type of function in C++ Language:- • Library function or pre-define function • User defined function. • Overloading function. • Inline function. • Friend function. • Static function. • Constructor function. • Destructor function. • Virtual function.
  • 9. LIBRARY FUNCTION • Library function are those which are predefined in C++ compiler. • The implementation part of pre-defined functions is available in library files that are .lib/.obj files. .lib or .obj files are contained pre-compiled code. • printf(), scanf(), clrscr(), pow() etc. are pre-defined functions.
  • 10. USER DEFINED FUNTION • These functions are created by programmer according to their requirement. • For example:-suppose you want to create a function for add two number then you create a function with name sum() this type of function is called user defined function.
  • 11. OVERLOADING FUNCTION • Whenever same method name is exiting multiple times in the same class with different number of parameter or different order of parameters or different types of parameters is known as function overloading. “Doing work in different way is called overloading”. Different way to overload the method:- 1. By Changing number of arguments or parameters 2. By Changing the data type
  • 12. By Changing Number of parameter
  • 13. By Changing the Data type
  • 14. INLINE FUNCTION IN C++ • An inline function is a combination of macro & function. At the time of declaration or definition, function name is preceded by word inline. • Function calls involve execution-time overhead. • Inline functions to help reduce function call overhead, especially for small functions.
  • 15. Example of Inline function in C++ inline void show() { cout<<“Hello World”; } int main() { show(); // Call it like a normal function } Inline function Hello World
  • 16. FRIEND FUNCTION IN C++ • A Friend function is a non-member function of the class that has been granted access to all private members of the class. • We simply declare the function within the class by a prefixing its declaration with keyword friend. • Function definition must not use keyword friend. • Definition of friend function is specified outside the class body and is not treated as a part of the class. • The major difference b/w member function and friend function is that the member function is accessed through the object while friend function requires object to be passed as parameter.
  • 17. FRIEND FUNCTION IN C++ Syntax: class ABC { …………… public: friend void xyz(object of class); };
  • 18. STATIC FUNTION IN C++ • We can define class members static using static keyword. • When we declare a member of a class as static no matter how many objects of the class are created. • There is only one copy of the static member. • A static member is shared by all objects of the class. • All static data is initialized to zero when the first object is created, if no other initialization is present. • Static member function called by :: inplace of . Operator.
  • 20. VIRTUAL FUNTION IN C++ • A virtual function a member function which is declared within base class and is re-defined (Overriden) by derived class. • They are mainly used to achieve Runtime polymorphism • Functions are declared with a virtual keyword in base class. • The resolving of function call is done at Run-time.
  • 21. EXAMPLE OF VIRTUAL FUNTION Class A { public: virtual void show(){ cout<<“Hello base classn”;} };class B : public A { public: void show() { cout<<“Hello derive class”; } };
  翻译: