SlideShare a Scribd company logo
1 of 22
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 overloadingKumar
 
C++ overloading
C++ overloadingC++ overloading
C++ overloadingsanya6900
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloadingPrincess Sam
 
Inline function
Inline functionInline function
Inline functionTech_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 overloadingArunaDevi63
 
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 overloadingRai 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 cpprajshreemuthiah
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversionsAmogh Kalyanshetti
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
Function overloading
Function overloadingFunction overloading
Function overloadingAshish Kelwa
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh 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 functiondipumaliy
 

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

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.pptxmiki304759
 
Function class in c++
Function class in c++Function class in c++
Function class in c++Kumar
 
object oriented programming language.pptx
object oriented programming language.pptxobject oriented programming language.pptx
object oriented programming language.pptxsyedabbas594247
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++Amresh Raj
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiSowmya 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 conversionHashni 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.pptAmanuelZewdie4
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C ProgrammingAnil Pokhrel
 
Functions and modular programming.pptx
Functions and modular programming.pptxFunctions and modular programming.pptx
Functions and modular programming.pptxzueZ3
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxsangeeta borde
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxSKUP1
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxLECO9
 

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

Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Deliverybabeytanya
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)Christopher H Felton
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewingbigorange77
 
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdfThe Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdfMilind Agarwal
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012rehmti665
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Personfurqan222004
 
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...akbard9823
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一3sw2qly1
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMartaLoveguard
 

Recently uploaded (20)

young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls In Mumbai Central Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
A Good Girl's Guide to Murder (A Good Girl's Guide to Murder, #1)
 
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Uttam Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
Denver Web Design brochure for public viewing
Denver Web Design brochure for public viewingDenver Web Design brochure for public viewing
Denver Web Design brochure for public viewing
 
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdfThe Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
The Intriguing World of CDR Analysis by Police: What You Need to Know.pdf
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
Call Girls South Delhi Delhi reach out to us at ☎ 9711199012
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Complet Documnetation for Smart Assistant Application for Disabled Person
Complet Documnetation   for Smart Assistant Application for Disabled PersonComplet Documnetation   for Smart Assistant Application for Disabled Person
Complet Documnetation for Smart Assistant Application for Disabled Person
 
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
Sushant Golf City / best call girls in Lucknow | Service-oriented sexy call g...
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in  Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Jamuna Vihar Delhi reach out to us at 🔝9953056974🔝
 
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
定制(CC毕业证书)美国美国社区大学毕业证成绩单原版一比一
 
Magic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptxMagic exist by Marta Loveguard - presentation.pptx
Magic exist by Marta Loveguard - presentation.pptx
 

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