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

More Related Content

What's hot

Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kumar
 
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
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 

What's hot (20)

Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
operator overloading in C++
operator overloading in C++operator overloading in C++
operator overloading in C++
 
C++ overloading
C++ overloadingC++ overloading
C++ overloading
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
Inline function
Inline functionInline function
Inline function
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
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
 
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
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversions
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Functions in c++
Functions in c++Functions in c++
Functions in 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++
operator overloading & type conversion in cpp over view || c++
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 

Similar to Function different types of funtion

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 concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
nirajmandaliya
 

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++
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptx
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
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
 
Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)Object oriented concepts & programming (2620003)
Object oriented concepts & programming (2620003)
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptx
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Functions
FunctionsFunctions
Functions
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
Python functions
Python functionsPython functions
Python functions
 

Recently uploaded

Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
aagad
 

Recently uploaded (12)

Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 

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”; } };