SlideShare a Scribd company logo
1 of 13
Programming with c++
By
S.Thanga rathinam(181619)
M.Vivek mani(181620)
II Bsc.mathematics(CA)
SBK college ,Aruppukottai
To
K.Padma Priya M.Sc(CS),M.Phill.
Assistant Professor
Dept of Mathematics(CA)
SBK college,Aruppukottai
Functions in c++
 The main function
 Function prototyping
 Call by reference
 Return by reference
 Inline function
The main function:
C does not specify any return type for the main()
function which is the starting point for the execution of a
program. The definition of main() would look this
Eg:
main()
{
//main program statements
}
This is perfectly vaild because the main() inc does not return
any value.
The main() returns a value of type int to the operating system
.
Eg :
int main();
int main(int argc,char*argv[]);
The functions that have a return value should use the
return statement for termination.
The main() function in c++ is
int main()
{
………….
………….
return 0;
}
Function prototyping:
Function prototyping is one of the majar improvements
added to c++ functions.
Function prototype is a decleration statement in the
calling program and is of the following form:
type function-name (argument-list);
The argument-list contains the types and names of
arguments that must be passed to be the function.
Eg:
float volume(int x, float y, float z);
we can also declare a function with an empty argument
list.
Void display( );
Call by reference:
In traditional c a function call passes arguments
by value. The called function reates a new set of variables and
copies the values of arguments into them.the function does
not have access to the actual variables in the calling program
and only work on the copies of values.
The reference variables inc++ permits us to pass
parameters to the function by reference .
void swape (int a, int b)
{
int t=a;
a=b;
b=t;
}
If m and n are two integer variables then function call
swap (m,n);
Return by reference:
A function can also returns a reference.
int & max (int &x, int &y)
{
if (x>y)
return x;
else
return y;
}
The return type of max() is int & the function returns
reference x or y .Then function call such as max(a,b) will yeild
a reference to either a or b dependingon their values .This
means that this function call can appear on the left hand side
of their assignment statement.
max (a,b) = -1;
Is legal and assigns -1 to a if it is larger , otherwise -1 to
b.
Inline functions:
An inline function is a function that is expended in line
when it is invoked.this inline fuctions are
inline function-header
{
function body
}
Eg:
inline double cube(double a)
{
return (a*a*a*);
}
It is easy to make a funtion inline.
Some of the situations where inline expansion may not work
are:
 For function returningvalues if a loop,a switch, or a goto
exists.
For a function not returning values if a return statement
exists.
If functions contains static variables.
If inline functions are recursive
Thankyou

More Related Content

What's hot

parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#khush_boo31
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structureRumman Ansari
 
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...hwbloom119
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++sanya6900
 
Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)SetuMaheshwari1
 
Types of function call
Types of function callTypes of function call
Types of function callArijitDhali
 
Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)Shujaat Abbas
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operatorsAnuja Lad
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Digvijaysinh Gohil
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++Neeru Mittal
 
Pointers in Programming
Pointers in ProgrammingPointers in Programming
Pointers in ProgrammingHamadZia1
 

What's hot (18)

parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
 
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
Consider the following C program: int fun(int *i) { *i += 5; return 4; } void...
 
operators and expressions in c++
 operators and expressions in c++ operators and expressions in c++
operators and expressions in c++
 
Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)Pointers lesson 5 (double pointer, call by value, call_by_reference)
Pointers lesson 5 (double pointer, call by value, call_by_reference)
 
Types of function call
Types of function callTypes of function call
Types of function call
 
11 functions
11 functions11 functions
11 functions
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
functions in C
functions in Cfunctions in C
functions in C
 
Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)Relational operators In C language (By: Shujaat Abbas)
Relational operators In C language (By: Shujaat Abbas)
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Concept of c
Concept of cConcept of c
Concept of c
 
Functions (Computer programming and utilization)
Functions (Computer programming and utilization)Functions (Computer programming and utilization)
Functions (Computer programming and utilization)
 
Increment and Decrement operators in C++
Increment and Decrement operators in C++Increment and Decrement operators in C++
Increment and Decrement operators in C++
 
oop Lecture 6
oop Lecture 6oop Lecture 6
oop Lecture 6
 
Pointers in Programming
Pointers in ProgrammingPointers in Programming
Pointers in Programming
 
Programming C Part 02
Programming C Part 02Programming C Part 02
Programming C Part 02
 

Similar to Functions in c++ (20)

Dti2143 chapter 5
Dti2143 chapter 5Dti2143 chapter 5
Dti2143 chapter 5
 
unit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdfunit3 part2 pcds function notes.pdf
unit3 part2 pcds function notes.pdf
 
Function
FunctionFunction
Function
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Function in c
Function in cFunction in c
Function in c
 
Functions
Functions Functions
Functions
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Function in c
Function in cFunction in c
Function in c
 
Unit 4.pdf
Unit 4.pdfUnit 4.pdf
Unit 4.pdf
 
Function
FunctionFunction
Function
 
functionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdffunctionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdf
 
UNIT3.pptx
UNIT3.pptxUNIT3.pptx
UNIT3.pptx
 
FUNCTIONS IN C PROGRAMMING.pdf
FUNCTIONS IN C PROGRAMMING.pdfFUNCTIONS IN C PROGRAMMING.pdf
FUNCTIONS IN C PROGRAMMING.pdf
 
Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions
FunctionsFunctions
Functions
 

More from Padma Kannan

More from Padma Kannan (13)

B tree
B treeB tree
B tree
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Java packags
Java packagsJava packags
Java packags
 
Java and c++
Java and c++Java and c++
Java and c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Functions of dbms
Functions  of dbmsFunctions  of dbms
Functions of dbms
 
Classes,object and methods java
Classes,object and methods javaClasses,object and methods java
Classes,object and methods java
 
Classes,object and methods jav
Classes,object and methods javClasses,object and methods jav
Classes,object and methods jav
 
Basic concept of oops
Basic concept of oopsBasic concept of oops
Basic concept of oops
 
LEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITYLEARNING BASES OF ACTICITY
LEARNING BASES OF ACTICITY
 
Social networking risks
Social networking risksSocial networking risks
Social networking risks
 
Inheritance
InheritanceInheritance
Inheritance
 
Excel2002
Excel2002Excel2002
Excel2002
 

Recently uploaded

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Functions in c++

  • 1. Programming with c++ By S.Thanga rathinam(181619) M.Vivek mani(181620) II Bsc.mathematics(CA) SBK college ,Aruppukottai To K.Padma Priya M.Sc(CS),M.Phill. Assistant Professor Dept of Mathematics(CA) SBK college,Aruppukottai
  • 2. Functions in c++  The main function  Function prototyping  Call by reference  Return by reference  Inline function
  • 3. The main function: C does not specify any return type for the main() function which is the starting point for the execution of a program. The definition of main() would look this Eg: main() { //main program statements } This is perfectly vaild because the main() inc does not return any value.
  • 4. The main() returns a value of type int to the operating system . Eg : int main(); int main(int argc,char*argv[]); The functions that have a return value should use the return statement for termination. The main() function in c++ is int main() { …………. …………. return 0; }
  • 5. Function prototyping: Function prototyping is one of the majar improvements added to c++ functions. Function prototype is a decleration statement in the calling program and is of the following form: type function-name (argument-list); The argument-list contains the types and names of arguments that must be passed to be the function.
  • 6. Eg: float volume(int x, float y, float z); we can also declare a function with an empty argument list. Void display( );
  • 7. Call by reference: In traditional c a function call passes arguments by value. The called function reates a new set of variables and copies the values of arguments into them.the function does not have access to the actual variables in the calling program and only work on the copies of values. The reference variables inc++ permits us to pass parameters to the function by reference .
  • 8. void swape (int a, int b) { int t=a; a=b; b=t; } If m and n are two integer variables then function call swap (m,n);
  • 9. Return by reference: A function can also returns a reference. int & max (int &x, int &y) { if (x>y) return x; else return y; }
  • 10. The return type of max() is int & the function returns reference x or y .Then function call such as max(a,b) will yeild a reference to either a or b dependingon their values .This means that this function call can appear on the left hand side of their assignment statement. max (a,b) = -1; Is legal and assigns -1 to a if it is larger , otherwise -1 to b.
  • 11. Inline functions: An inline function is a function that is expended in line when it is invoked.this inline fuctions are inline function-header { function body } Eg: inline double cube(double a) { return (a*a*a*); }
  • 12. It is easy to make a funtion inline. Some of the situations where inline expansion may not work are:  For function returningvalues if a loop,a switch, or a goto exists. For a function not returning values if a return statement exists. If functions contains static variables. If inline functions are recursive