SlideShare a Scribd company logo
5
Most read
7
Most read
8
Most read
Functions
• A function is a group of statements that together
perform a task.
• main() -> mandatory function =
• Various programs define additional functions.
• A function declaration tells the compiler about a
function's name, return type, and parameters. A
function definition provides the actual body of the
function.
Function Declaration
• A function can be defined as:
Syntax : return_type function_name(arguments)
{
body of the function
}
For e.g :
int add(int a,int b)
{
return a+b;
}
Calling a Function
• A function can be called
in a main() function or in
other functions.
• When it is called inside
itself than it called as
recursive function.
main()/function_1()
{
body
function(passing values);
}
For e.g :
main()
{
int a,b;
cout<<“Sum=“<<add(a,b);
}
int add(int x,int y)
{
return x+y;
}
Inline Functions
• If a function is inline than:
– Compiler puts its code at the place
where it is called at compile time
– To define a function as inline
function
• use the keyword “inline” just
before the return type.
– The compiler ignore the inline
qualifier in case defined function is
more than a line.
inline return_type
function_name(args)
{
//one line code
}
Inline Function (example)
#include <iostream>
using namespace std;
inline int Max(int x, int y)
{
return (x > y)? x : y;
}
// Main function for the program
int main( )
{
cout << "Max (20,10): " << Max(20,10) << endl;
cout << "Max (0,200): " << Max(0,200) << endl;
cout << "Max (100,1010): " << Max(100,1010) <<
endl;
return 0;
}
Output:
Max (20,10): 20
Max (0,200): 200
Max (100,1010): 1010
Why Inline functions
• Objective of using functions:
– To save memory space, when a
function is likely to be called
many times.
Jumping to a function
Saving the registers
Pushing arguments in to the
stack
Returning to the calling
function
• When a function is small enough
(only one line of code) these
things would be a wastage of
time and resources.
Function with Default Arguments
• A default argument is a value
provided in function
declaration that is
automatically assigned by the
compiler if caller of the
function doesn’t provide a
value for the argument with
default value.
return _type f_name (arg1,arg2,arg3=value)
• When a default argument is placed then all the other arguments
after that must be default arguments only.
• That says the default arguments must placed on right most side of
all the arguments collectively
Default arguments (example)
int sum(int x, int y, int z=0, int w=0)
{
return (x + y + z + w);
}
int main()
{
cout << sum(10, 15) << endl;
cout << sum(10, 15, 25) << endl;
cout << sum(10, 15, 25, 30) <<
endl;
return 0;
}
Output:
25
50
80
Default Arguments
• They may come in handy when some arguments
are having the same values.
– For e.g. Bank interest may remain the same for all
the customers for a particular period of deposit.
Inline Functions and Default arguments

More Related Content

PPTX
Templates in c++
ThamizhselviKrishnam
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPTX
C functions
University of Potsdam
 
PPTX
Polymorphism in java
Elizabeth alexander
 
PPTX
Inline function
Tech_MX
 
PDF
Function overloading ppt
Prof. Dr. K. Adisesha
 
PPTX
Inheritance in c++
Vineeta Garg
 
PPTX
this keyword in Java.pptx
ParvizMirzayev2
 
Templates in c++
ThamizhselviKrishnam
 
Data Types & Variables in JAVA
Ankita Totala
 
Polymorphism in java
Elizabeth alexander
 
Inline function
Tech_MX
 
Function overloading ppt
Prof. Dr. K. Adisesha
 
Inheritance in c++
Vineeta Garg
 
this keyword in Java.pptx
ParvizMirzayev2
 

What's hot (20)

PDF
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
Edureka!
 
PPTX
Functions in c language
tanmaymodi4
 
PDF
Exception handling
Pranali Chaudhari
 
PPTX
Functions in Python
Kamal Acharya
 
PPTX
Packages In Python Tutorial
Simplilearn
 
PPTX
Method overloading
Lovely Professional University
 
PPTX
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
PPTX
Python: Modules and Packages
Damian T. Gordon
 
PPT
Operator Overloading
Nilesh Dalvi
 
PPTX
Error managing and exception handling in java
Andhra University
 
PPTX
Multiple inheritance in c++
Sujan Mia
 
PPSX
Files in c++
Selvin Josy Bai Somu
 
PPTX
Friend function
zindadili
 
PPTX
classes and objects in C++
HalaiHansaika
 
PPT
Binary operator overloading
BalajiGovindan5
 
PPTX
Interfaces in java
Shiv Mehmi
 
PPTX
Inheritance In Java
Darpan Chelani
 
PPT
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
PPT
OOP in C++
ppd1961
 
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
Edureka!
 
Functions in c language
tanmaymodi4
 
Exception handling
Pranali Chaudhari
 
Functions in Python
Kamal Acharya
 
Packages In Python Tutorial
Simplilearn
 
Method overloading
Lovely Professional University
 
Virtual function in C++ Pure Virtual Function
Kamlesh Makvana
 
Python: Modules and Packages
Damian T. Gordon
 
Operator Overloading
Nilesh Dalvi
 
Error managing and exception handling in java
Andhra University
 
Multiple inheritance in c++
Sujan Mia
 
Files in c++
Selvin Josy Bai Somu
 
Friend function
zindadili
 
classes and objects in C++
HalaiHansaika
 
Binary operator overloading
BalajiGovindan5
 
Interfaces in java
Shiv Mehmi
 
Inheritance In Java
Darpan Chelani
 
Introduction to method overloading &amp; method overriding in java hdm
Harshal Misalkar
 
OOP in C++
ppd1961
 
Ad

Viewers also liked (20)

PPTX
functions of C++
tarandeep_kaur
 
PPT
friend function(c++)
Ritika Sharma
 
PPT
C++ Function
Hajar
 
PPTX
Function C++
Shahzad Afridi
 
PPT
FUNCTIONS IN c++ PPT
03062679929
 
PPT
Functions in C++
Sachin Sharma
 
PPT
Friends function and_classes
asadsardar
 
PPTX
Inline function in C++
Jenish Patel
 
PPT
Functions
Online
 
PPT
Functions in C++
Nikhil Pandit
 
PPTX
Diodes
Nikhil Pandit
 
PDF
Chapter23 friend-function-friend-class
Deepak Singh
 
PPTX
Object as function argument , friend and static function by shahzad younas
Shahzad Younas
 
PPT
RECURSION IN C
v_jk
 
PPTX
Safety rules and earthing
Nikhil Pandit
 
PPT
Simplifies and normal forms - Theory of Computation
Nikhil Pandit
 
PPTX
Friend functions
Megha Singh
 
PPT
Linear function and slopes of a line
Jerlyn Fernandez
 
PPT
Software Coding- Software Coding
Nikhil Pandit
 
PPT
Arrays Basics
Nikhil Pandit
 
functions of C++
tarandeep_kaur
 
friend function(c++)
Ritika Sharma
 
C++ Function
Hajar
 
Function C++
Shahzad Afridi
 
FUNCTIONS IN c++ PPT
03062679929
 
Functions in C++
Sachin Sharma
 
Friends function and_classes
asadsardar
 
Inline function in C++
Jenish Patel
 
Functions
Online
 
Functions in C++
Nikhil Pandit
 
Chapter23 friend-function-friend-class
Deepak Singh
 
Object as function argument , friend and static function by shahzad younas
Shahzad Younas
 
RECURSION IN C
v_jk
 
Safety rules and earthing
Nikhil Pandit
 
Simplifies and normal forms - Theory of Computation
Nikhil Pandit
 
Friend functions
Megha Singh
 
Linear function and slopes of a line
Jerlyn Fernandez
 
Software Coding- Software Coding
Nikhil Pandit
 
Arrays Basics
Nikhil Pandit
 
Ad

Similar to Inline Functions and Default arguments (20)

PPT
Function
yash patel
 
PPTX
Python_Functions_Unit1.pptx
Koteswari Kasireddy
 
PPTX
Functions
Golda Margret Sheeba J
 
PPTX
Chp8_C++_Functions_Part2_User-defined functions.pptx
ssuser10ed71
 
PPTX
Chapter 4
temkin abdlkader
 
PPTX
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
tony8553004135
 
PPTX
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
PPT
16717 functions in C++
LPU
 
PPTX
Functions in C++ (OOP)
Faizan Janjua
 
PPT
Chap 5 c++
Venkateswarlu Vuggam
 
PDF
Chap 5 c++
Venkateswarlu Vuggam
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PDF
10. funtions and closures IN SWIFT PROGRAMMING
LOVELY PROFESSIONAL UNIVERSITY
 
PPTX
Lab 2 Math functions c++ programming.pptx
usamatanver786
 
PPT
Review functions
Kgr Sushmitha
 
PPTX
Learning C++ - Functions in C++ 3
Ali Aminian
 
PPT
Inbuilt Functions in C++ computer language.ppt
AjayLobo1
 
PPTX
Function in C++, Methods in C++ coding programming
estorebackupr
 
PPTX
functioninpython-1.pptx
SulekhJangra
 
PPTX
FUNCTIONS IN C.pptx
LECO9
 
Function
yash patel
 
Python_Functions_Unit1.pptx
Koteswari Kasireddy
 
Chp8_C++_Functions_Part2_User-defined functions.pptx
ssuser10ed71
 
Chapter 4
temkin abdlkader
 
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
tony8553004135
 
CH.4FUNCTIONS IN C (1).pptx
sangeeta borde
 
16717 functions in C++
LPU
 
Functions in C++ (OOP)
Faizan Janjua
 
Functions in Python Programming Language
BeulahS2
 
10. funtions and closures IN SWIFT PROGRAMMING
LOVELY PROFESSIONAL UNIVERSITY
 
Lab 2 Math functions c++ programming.pptx
usamatanver786
 
Review functions
Kgr Sushmitha
 
Learning C++ - Functions in C++ 3
Ali Aminian
 
Inbuilt Functions in C++ computer language.ppt
AjayLobo1
 
Function in C++, Methods in C++ coding programming
estorebackupr
 
functioninpython-1.pptx
SulekhJangra
 
FUNCTIONS IN C.pptx
LECO9
 

More from Nikhil Pandit (6)

PPT
Use case Diagram and Sequence Diagram
Nikhil Pandit
 
PPTX
The scope of contribution
Nikhil Pandit
 
PPTX
4 stroke diesel engine
Nikhil Pandit
 
PPT
CHAIN RULE AND IMPLICIT FUNCTION
Nikhil Pandit
 
PPTX
Register transfer and micro-operation
Nikhil Pandit
 
PPTX
Spyware and rootkit
Nikhil Pandit
 
Use case Diagram and Sequence Diagram
Nikhil Pandit
 
The scope of contribution
Nikhil Pandit
 
4 stroke diesel engine
Nikhil Pandit
 
CHAIN RULE AND IMPLICIT FUNCTION
Nikhil Pandit
 
Register transfer and micro-operation
Nikhil Pandit
 
Spyware and rootkit
Nikhil Pandit
 

Recently uploaded (20)

PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PPTX
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PPTX
ternal cell structure: leadership, steering
hodeeesite4
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PPTX
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
PPTX
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PPTX
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
PPTX
unit 3a.pptx material management. Chapter of operational management
atisht0104
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
EE3303-EM-I 25.7.25 electrical machines.pptx
Nagen87
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
Introduction to Data Science: data science process
ShivarkarSandip
 
ternal cell structure: leadership, steering
hodeeesite4
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
flutter Launcher Icons, Splash Screens & Fonts
Ahmed Mohamed
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
unit 3a.pptx material management. Chapter of operational management
atisht0104
 

Inline Functions and Default arguments

  • 1. Functions • A function is a group of statements that together perform a task. • main() -> mandatory function = • Various programs define additional functions. • A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
  • 2. Function Declaration • A function can be defined as: Syntax : return_type function_name(arguments) { body of the function } For e.g : int add(int a,int b) { return a+b; }
  • 3. Calling a Function • A function can be called in a main() function or in other functions. • When it is called inside itself than it called as recursive function. main()/function_1() { body function(passing values); } For e.g : main() { int a,b; cout<<“Sum=“<<add(a,b); } int add(int x,int y) { return x+y; }
  • 4. Inline Functions • If a function is inline than: – Compiler puts its code at the place where it is called at compile time – To define a function as inline function • use the keyword “inline” just before the return type. – The compiler ignore the inline qualifier in case defined function is more than a line. inline return_type function_name(args) { //one line code }
  • 5. Inline Function (example) #include <iostream> using namespace std; inline int Max(int x, int y) { return (x > y)? x : y; } // Main function for the program int main( ) { cout << "Max (20,10): " << Max(20,10) << endl; cout << "Max (0,200): " << Max(0,200) << endl; cout << "Max (100,1010): " << Max(100,1010) << endl; return 0; } Output: Max (20,10): 20 Max (0,200): 200 Max (100,1010): 1010
  • 6. Why Inline functions • Objective of using functions: – To save memory space, when a function is likely to be called many times. Jumping to a function Saving the registers Pushing arguments in to the stack Returning to the calling function • When a function is small enough (only one line of code) these things would be a wastage of time and resources.
  • 7. Function with Default Arguments • A default argument is a value provided in function declaration that is automatically assigned by the compiler if caller of the function doesn’t provide a value for the argument with default value. return _type f_name (arg1,arg2,arg3=value) • When a default argument is placed then all the other arguments after that must be default arguments only. • That says the default arguments must placed on right most side of all the arguments collectively
  • 8. Default arguments (example) int sum(int x, int y, int z=0, int w=0) { return (x + y + z + w); } int main() { cout << sum(10, 15) << endl; cout << sum(10, 15, 25) << endl; cout << sum(10, 15, 25, 30) << endl; return 0; } Output: 25 50 80
  • 9. Default Arguments • They may come in handy when some arguments are having the same values. – For e.g. Bank interest may remain the same for all the customers for a particular period of deposit.