SlideShare a Scribd company logo
TRINITY INSTITUTE OF PROFESSIONAL
STUDIESSector – 9, DwarkaInstitutional Area, New Delhi-75
Affiliated Institution of G.G.S.IP.U, Delhi
Object Oriented Programming
using C++
Paper ID : 20209
Course : BCA
InlineFuntions
By HimjaSethi
Asstt. Prof. (IT)
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
Inline Functions
• A function in C++ can be treated as a macro if
the
keyword inline precedes its definition
• Syntax of representing inline function:
inline ReturnType
FunctionName(Parameters)
{
// body of the main function
}
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
Syntax : Inline Function
Function to find square of a number :
inline float square(float x)
{
x = x* x;
return (x);
}
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
Advantages: Inline Functions
• There is no explicit function call; the function body is
substituted at the point of inline function call
• Runtime overhead for function linkage mechanism is
reduced.
• The execution time of the function square() is less
than the time required to establish a linkage
between the function caller and the callee.
• Inline functions provide flexibility and benefits of
modular programming.
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
Advantages : Inline Functions
• Inline functions provide flexibility and benefits of
modular programming.
• Provide computational speedups of macros.
• It is advisable to define functions having small body
as inline functions.
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
Sample Program
#include <iostream.h>
inline float square(float x)
{
x = x* x;
return (x);
}
void main()
{
float num;
cout<<“ Enter a number <float>”;
cin>>num;
cout<< “Its square = “ << square (num);
}
Gets replaced by the instructions
of square() function body by
compiler
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
Outside Member Functions as Inline
• Member functions declared outside the class
declaration can be made inline by prefixing
the inline to its definition as shown:
inline ReturnType
ClassName::MemberFunctionName(Argument
s )
{
…
}
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
When to use inline Functions
• In general, inline functions should not be used
• If a fully developed and tested program runs too slowly and
shows bottlenecks in certain functions then it can be
considered to use inline functions. A profiler ( which runs the
program and determines where most of the execution time is
spent) can be used in deciding such an optimization.
• When member functions consist of one very simple
statement such as the return statement in the example
below:
inline int date :: getday()
{
return day;
}
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
When to use inline Functions
• It is only useful to implement an inline function if the
time spent during a function call is more compared to
the function body execution time. An example where
an inline function has no effect at all is the following:
inline void date :: show()
{
cout << day << “ –” << month<< “-” << year << endl;
}
The above function takes relatively longer time to execute.
The effect of conversion of the function show() to inline
would
lead to reduction in execution time.
TRINITY INSTITUTE OF PROFESSIONAL STUDIES
Sector – 9, DwarkaInstitutional Area, New Delhi-75
Disadvantage of Inline Function
• The actual code is inserted by the compiler
and therefore it should be known at the
compile time. Hence, an inline function can
not be located in a run-time library.

More Related Content

PPTX
PPTX
Functions in programming language
PDF
DSA 103 Object Oriented Programming :: Week 2
PPTX
07. Virtual Functions
PDF
inline function
PPTX
INLINE FUNCTION IN C++
PPTX
inline function
Functions in programming language
DSA 103 Object Oriented Programming :: Week 2
07. Virtual Functions
inline function
INLINE FUNCTION IN C++
inline function

Similar to Object oriented programming using c++ (20)

PPTX
Inline functions
PPTX
Inline function
PPTX
Study of Inline Function in C++ with examples
PPTX
06 - This pointer, Inline, Array of Objects.pptx
DOCX
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
PPTX
INLINE FUNCTIONS IOT68.pptx
PPTX
Function in C++, Methods in C++ coding programming
PPTX
Inline functions in c++
DOCX
Inline function(oops)
PDF
Computer_Programming_Part_II_Segment_02.pdf
PPTX
Inline function in C++
PDF
Function overloading ppt
PPSX
Chapter-4_OOP aare temi Lena na petna chho loda
PDF
Function overloading
PPTX
Inline function in C++
PPTX
Object Oriented Programming using C++ Unit 1
PPTX
Programming in c++ ppt
PPTX
Programming in c++ ppt
PPTX
Functions in c++
PPTX
Array within a class
Inline functions
Inline function
Study of Inline Function in C++ with examples
06 - This pointer, Inline, Array of Objects.pptx
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
INLINE FUNCTIONS IOT68.pptx
Function in C++, Methods in C++ coding programming
Inline functions in c++
Inline function(oops)
Computer_Programming_Part_II_Segment_02.pdf
Inline function in C++
Function overloading ppt
Chapter-4_OOP aare temi Lena na petna chho loda
Function overloading
Inline function in C++
Object Oriented Programming using C++ Unit 1
Programming in c++ ppt
Programming in c++ ppt
Functions in c++
Array within a class
Ad

More from Trinity Dwarka (20)

PPTX
Why BAJMC in Trinity Dwarka
PPTX
Career Options after BCA
PPTX
Principles of Management-Management-Concept & Meaning
PPTX
Principles of Management- Management Process & Functions
PPTX
Principles of Management- Managerial Levels & Roles-
PPTX
Management-Concept & Meaning
PPTX
Principles of Management- Planning
PPTX
Organizing Authority & Responsibility- Principles of Management
PPTX
Staffing- Principles of Management
PPTX
Directing-Principles of Management
PPTX
Dimensional Modelling-Data Warehouse & Data Mining
PPTX
Data Preprocessing- Data Warehouse & Data Mining
PPTX
Computer Networks- Network Basics
PPTX
Java Programming- Introduction to Java Applet Programs
PPTX
Linux Environment- Linux vs Unix
PPTX
Linux Environment- Linux Basics
PPTX
BCA-Mobile Computing- BASICS OF MOBILE COMPUTING
PPTX
INTRODUCTION TO INFORMATION TECHNOLOGY- IT Basics
PPTX
Database Management System
PPTX
JAVA PROGRAMMING- OOP Concept
Why BAJMC in Trinity Dwarka
Career Options after BCA
Principles of Management-Management-Concept & Meaning
Principles of Management- Management Process & Functions
Principles of Management- Managerial Levels & Roles-
Management-Concept & Meaning
Principles of Management- Planning
Organizing Authority & Responsibility- Principles of Management
Staffing- Principles of Management
Directing-Principles of Management
Dimensional Modelling-Data Warehouse & Data Mining
Data Preprocessing- Data Warehouse & Data Mining
Computer Networks- Network Basics
Java Programming- Introduction to Java Applet Programs
Linux Environment- Linux vs Unix
Linux Environment- Linux Basics
BCA-Mobile Computing- BASICS OF MOBILE COMPUTING
INTRODUCTION TO INFORMATION TECHNOLOGY- IT Basics
Database Management System
JAVA PROGRAMMING- OOP Concept
Ad

Recently uploaded (20)

PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Structure & Organelles in detailed.
The Final Stretch: How to Release a Game and Not Die in the Process.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Microbial diseases, their pathogenesis and prophylaxis
Open Quiz Monsoon Mind Game Final Set.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cardiovascular Pharmacology for pharmacy students.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
TR - Agricultural Crops Production NC III.pdf
Open folder Downloads.pdf yes yes ges yes
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PPH.pptx obstetrics and gynecology in nursing

Object oriented programming using c++

  • 1. TRINITY INSTITUTE OF PROFESSIONAL STUDIESSector – 9, DwarkaInstitutional Area, New Delhi-75 Affiliated Institution of G.G.S.IP.U, Delhi Object Oriented Programming using C++ Paper ID : 20209 Course : BCA InlineFuntions By HimjaSethi Asstt. Prof. (IT)
  • 2. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 Inline Functions • A function in C++ can be treated as a macro if the keyword inline precedes its definition • Syntax of representing inline function: inline ReturnType FunctionName(Parameters) { // body of the main function }
  • 3. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 Syntax : Inline Function Function to find square of a number : inline float square(float x) { x = x* x; return (x); }
  • 4. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 Advantages: Inline Functions • There is no explicit function call; the function body is substituted at the point of inline function call • Runtime overhead for function linkage mechanism is reduced. • The execution time of the function square() is less than the time required to establish a linkage between the function caller and the callee. • Inline functions provide flexibility and benefits of modular programming.
  • 5. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 Advantages : Inline Functions • Inline functions provide flexibility and benefits of modular programming. • Provide computational speedups of macros. • It is advisable to define functions having small body as inline functions.
  • 6. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 Sample Program #include <iostream.h> inline float square(float x) { x = x* x; return (x); } void main() { float num; cout<<“ Enter a number <float>”; cin>>num; cout<< “Its square = “ << square (num); } Gets replaced by the instructions of square() function body by compiler
  • 7. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 Outside Member Functions as Inline • Member functions declared outside the class declaration can be made inline by prefixing the inline to its definition as shown: inline ReturnType ClassName::MemberFunctionName(Argument s ) { … }
  • 8. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 When to use inline Functions • In general, inline functions should not be used • If a fully developed and tested program runs too slowly and shows bottlenecks in certain functions then it can be considered to use inline functions. A profiler ( which runs the program and determines where most of the execution time is spent) can be used in deciding such an optimization. • When member functions consist of one very simple statement such as the return statement in the example below: inline int date :: getday() { return day; }
  • 9. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 When to use inline Functions • It is only useful to implement an inline function if the time spent during a function call is more compared to the function body execution time. An example where an inline function has no effect at all is the following: inline void date :: show() { cout << day << “ –” << month<< “-” << year << endl; } The above function takes relatively longer time to execute. The effect of conversion of the function show() to inline would lead to reduction in execution time.
  • 10. TRINITY INSTITUTE OF PROFESSIONAL STUDIES Sector – 9, DwarkaInstitutional Area, New Delhi-75 Disadvantage of Inline Function • The actual code is inserted by the compiler and therefore it should be known at the compile time. Hence, an inline function can not be located in a run-time library.