SlideShare a Scribd company logo
3
Most read
12
Most read
14
Most read
Amity School of Engineering & Technology
1
FUNCTIONS
Presented By:
Shivani Dubey
Priyanka
Yadav
Maaz Hasan
Amity School of Engineering & Technology
CONTENTS• Introduction.
• The Main Function.
• Function Prototyping.
• Call by Reference.
• Return by Reference.
• Inline Function.
• Default Arguments.
• Constant Arguments.
• Recursion.
• Function Overloading.
• Friend and Virtual Function.
• Math Library Function. 2
Amity School of Engineering & Technology
INTRODUCTION
• Divide and conquer :
– Construct a program from smaller pieces or components.
– These smaller pieces are called modules.
– Each piece more manageable than the original program.
– Building blocks of C++.
3
Amity School of Engineering & Technology
• void show(); //function declaration
main()
{
….
show(); //function call
….
}
void show(); //function definition
{
… //function body
…
} 4
AN EXAMPLE
Amity School of Engineering & Technology
THE MAIN FUNCTION
5
• When a program begins running,
the system calls the function main,
which marks the entry point of the
program.
• By default, main has the storage
class extern.
• Every program must have one
function named main, and the
following constraints.
Amity School of Engineering & Technology
FUNCTION PROTOTYPING
• A Function Prototype in C++ is a declaration of
a function that omits the function body but does specify the
function's return type, name and argument types. While a
function definition specifies what a function does, a function
prototype can be thought of as specifying its interface.
6
Amity School of Engineering & Technology
CALL BY REFERENCE
• The Call by Reference method of passing arguments to a
function copies the reference of an argument into the formal
parameter. Inside the function, the reference is used to access
the actual argument used in the call. This means that changes
made to the parameter affect the passed argument.
7
Amity School of Engineering & Technology
AN EXAMPLE
8
#include <iostream>
using namespace std;
// function declaration
void swap(int &x, int &y);
int main ()
{ // local variable declaration:
int a = 100; int b = 200;
cout << "Before swap, value of a :" << a << endl;
cout << "Before swap, value of b :" << b << endl; /* calling a
function to swap the values using variable reference.*/
swap(a, b); cout << "After swap, value of a :" << a << endl;
cout << "After swap, value of b :" << b << endl;
return 0;
}
Amity School of Engineering & Technology
RETURN BY REFERENCE
• A C++ program can be made easier to read and maintain by
using references rather than pointers. A C++ function can
return a reference in a similar way as it returns a pointer.
• When a function returns a reference, it returns an implicit
pointer to its return value. This way, a function can be used on
the left side of an assignment statement.
9
Amity School of Engineering & Technology
INLINE FUNCTION
• An Inline Function the programme
That has requested that the compiler insert
the complete body of the function in
every place that the function is called,
rather than generating code to call the
function in the one place it is defined.
10
Amity School of Engineering & Technology
DEFAULT ARGUEMENTS
• In computer programming, a default argument is an
argument to a function that a programmer is not required to
specify. In most programming languages, functions may take
one or more arguments.
• The default argument must be implicitly convertible to the
parameter type.
11
Amity School of Engineering & Technology
CONSTANT ARGUEMENTS
• The const variable can be declared using const keyword.
• The const keyword makes variable value stable.
• The constant variable should be initialized while declaring.
Syntax:
• (a) const <variable name> = <value>;
• (b) <function name> (const <type>*<variable name>;)
• (c) int const x // in valid
• (d) int const x =5 // valid
12
Amity School of Engineering & Technology
RECURSION
• Recursive functions:
– Functions that call themselves
– Can only solve a base case
– Divide a problem up into
• What it can do.
• What it cannot do.
• What it cannot do resembles
• original problem.
• The function launches a new copy of itself
(recursion step) to solve what it cannot do
13
Amity School of Engineering & Technology
FUNCTION OVERLOADING
• Function overloading is a feature found in that allows
creating several methods with the same name which differ
from each other in the type of the input and the output of the
function. It is simply defined as the ability of one function to
perform different tasks.
14
Amity School of Engineering & Technology
FRIEND & VIRTUAL FUNCTION
15
• A Friend Function access to private and protected data in that
class that it would not normally be able to as if the data was public.
• A Function of global or namespace scope may be declared as friend
of both classes.
• A Virtual Function is a function or method whose behaviour can
be overridden within an inheriting class by a function with the
same signature. This concept is an important part of
the polymorphism portion of Object-Oriented Programming (OOP).
Amity School of Engineering & Technology
MATH LIBRARY FUNCTION
• C Mathematical Operations are a group of functions in
the Standard Library of the C programming
language implementing basic mathematical functions.
16
Amity School of Engineering & Technology
REFERENCES
• Wikipedia.com.
• C++ By Yashwant Kanetkar.
• C++ By E Balagurusamy.
17
Amity School of Engineering & Technology
18

More Related Content

PPT
Functions in C++
PPTX
classes and objects in C++
PPTX
Functions in c++
PDF
Constructor and Destructor
PDF
Operator overloading
PPT
Operators in C++
PPT
16717 functions in C++
 
PDF
Constructors and Destructors
Functions in C++
classes and objects in C++
Functions in c++
Constructor and Destructor
Operator overloading
Operators in C++
16717 functions in C++
 
Constructors and Destructors

What's hot (20)

PPTX
Operator overloading and type conversion in cpp
PPT
FUNCTIONS IN c++ PPT
PPTX
Constructor in java
PPTX
Polymorphism In c++
PPTX
Classes, objects in JAVA
PPTX
Constructor and destructor
PPT
Class and object in C++
PPT
C++ Function
PPTX
Member Function in C++
PPTX
Data types in c++
PPTX
Functions in c language
PDF
Methods in Java
PPTX
Object oriented programming
PDF
C++ tokens and expressions
PPTX
Functions in c
PDF
Function overloading ppt
PPTX
Inline function in C++
PDF
Object oriented approach in python programming
PDF
Operator overloading C++
PPTX
Static Data Members and Member Functions
Operator overloading and type conversion in cpp
FUNCTIONS IN c++ PPT
Constructor in java
Polymorphism In c++
Classes, objects in JAVA
Constructor and destructor
Class and object in C++
C++ Function
Member Function in C++
Data types in c++
Functions in c language
Methods in Java
Object oriented programming
C++ tokens and expressions
Functions in c
Function overloading ppt
Inline function in C++
Object oriented approach in python programming
Operator overloading C++
Static Data Members and Member Functions
Ad

Viewers also liked (20)

PPTX
functions of C++
PPT
Functions in C++
PPT
Lec 45.46- virtual.functions
PPS
Inheritance
PPTX
OOP C++
PDF
Netw450 advanced network security with lab entire class
PDF
C++ L05-Functions
PPTX
Functions c++ مشروع
PDF
Network-security muhibullah aman-first edition-in Persian
PDF
Network Security in 2016
PPTX
C++ lecture 03
DOCX
The Algebra of Functions
PPTX
Learning C++ - Functions in C++ 3
PDF
Basic openCV Functions Using CPP
PPT
Lec 42.43 - virtual.functions
PPTX
Functions in C++
PPTX
Functions in C++
PDF
Web Applications Under Attack: Why Network Security Solutions Leave You Exposed
PPT
Functions in c++
functions of C++
Functions in C++
Lec 45.46- virtual.functions
Inheritance
OOP C++
Netw450 advanced network security with lab entire class
C++ L05-Functions
Functions c++ مشروع
Network-security muhibullah aman-first edition-in Persian
Network Security in 2016
C++ lecture 03
The Algebra of Functions
Learning C++ - Functions in C++ 3
Basic openCV Functions Using CPP
Lec 42.43 - virtual.functions
Functions in C++
Functions in C++
Web Applications Under Attack: Why Network Security Solutions Leave You Exposed
Functions in c++
Ad

Similar to Functions in c++ (20)

PPTX
FUNCTIONS, CLASSES AND OBJECTS.pptx
PDF
Functions in C++
PPTX
Functions in c++,
PPTX
C++ Functions.pptx
PPTX
OOP-Module-1-Section-4-LectureNo1-5.pptx
PDF
Function overloading
PPTX
Fundamental of programming Fundamental of programming
PPT
PPTX
Functions1
PPTX
C++_Functions_Detailed_Presentation.pptx
PPTX
Function in C++, Methods in C++ coding programming
PPT
Material 3 (4).ppt this ppt is about the
PPT
C++ Functions.ppt
PPT
power point presentation on object oriented programming functions concepts
PPTX
Function Overloading Call by value and call by reference
PPT
PDF
PPTX
6. Functions in C ++ programming object oriented programming
PPTX
Chapter 1 (2) array and structure r.pptx
PPT
Chapter 1.ppt
FUNCTIONS, CLASSES AND OBJECTS.pptx
Functions in C++
Functions in c++,
C++ Functions.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
Function overloading
Fundamental of programming Fundamental of programming
Functions1
C++_Functions_Detailed_Presentation.pptx
Function in C++, Methods in C++ coding programming
Material 3 (4).ppt this ppt is about the
C++ Functions.ppt
power point presentation on object oriented programming functions concepts
Function Overloading Call by value and call by reference
6. Functions in C ++ programming object oriented programming
Chapter 1 (2) array and structure r.pptx
Chapter 1.ppt

More from Maaz Hasan (7)

PPTX
Social Media Intelligence
PPT
Quantum dots
PPT
D’ecrivez la Cuisine ou la gastronomies Françoise: Fromage
PPT
Degrading Reading Habits and its Impact on Quality of Education
PPTX
Pattern Recognition
PPT
Population explosion
PPT
Recent Technology in Data Communication
Social Media Intelligence
Quantum dots
D’ecrivez la Cuisine ou la gastronomies Françoise: Fromage
Degrading Reading Habits and its Impact on Quality of Education
Pattern Recognition
Population explosion
Recent Technology in Data Communication

Recently uploaded (20)

PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Geodesy 1.pptx...............................................
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Digital Logic Computer Design lecture notes
DOCX
573137875-Attendance-Management-System-original
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
Mechanical Engineering MATERIALS Selection
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPT
Project quality management in manufacturing
PPTX
Welding lecture in detail for understanding
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
additive manufacturing of ss316l using mig welding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Structs to JSON How Go Powers REST APIs.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Internet of Things (IOT) - A guide to understanding
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Geodesy 1.pptx...............................................
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Digital Logic Computer Design lecture notes
573137875-Attendance-Management-System-original
OOP with Java - Java Introduction (Basics)
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Mechanical Engineering MATERIALS Selection
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Project quality management in manufacturing
Welding lecture in detail for understanding
Lecture Notes Electrical Wiring System Components
additive manufacturing of ss316l using mig welding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Structs to JSON How Go Powers REST APIs.pdf

Functions in c++

  • 1. Amity School of Engineering & Technology 1 FUNCTIONS Presented By: Shivani Dubey Priyanka Yadav Maaz Hasan
  • 2. Amity School of Engineering & Technology CONTENTS• Introduction. • The Main Function. • Function Prototyping. • Call by Reference. • Return by Reference. • Inline Function. • Default Arguments. • Constant Arguments. • Recursion. • Function Overloading. • Friend and Virtual Function. • Math Library Function. 2
  • 3. Amity School of Engineering & Technology INTRODUCTION • Divide and conquer : – Construct a program from smaller pieces or components. – These smaller pieces are called modules. – Each piece more manageable than the original program. – Building blocks of C++. 3
  • 4. Amity School of Engineering & Technology • void show(); //function declaration main() { …. show(); //function call …. } void show(); //function definition { … //function body … } 4 AN EXAMPLE
  • 5. Amity School of Engineering & Technology THE MAIN FUNCTION 5 • When a program begins running, the system calls the function main, which marks the entry point of the program. • By default, main has the storage class extern. • Every program must have one function named main, and the following constraints.
  • 6. Amity School of Engineering & Technology FUNCTION PROTOTYPING • A Function Prototype in C++ is a declaration of a function that omits the function body but does specify the function's return type, name and argument types. While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface. 6
  • 7. Amity School of Engineering & Technology CALL BY REFERENCE • The Call by Reference method of passing arguments to a function copies the reference of an argument into the formal parameter. Inside the function, the reference is used to access the actual argument used in the call. This means that changes made to the parameter affect the passed argument. 7
  • 8. Amity School of Engineering & Technology AN EXAMPLE 8 #include <iostream> using namespace std; // function declaration void swap(int &x, int &y); int main () { // local variable declaration: int a = 100; int b = 200; cout << "Before swap, value of a :" << a << endl; cout << "Before swap, value of b :" << b << endl; /* calling a function to swap the values using variable reference.*/ swap(a, b); cout << "After swap, value of a :" << a << endl; cout << "After swap, value of b :" << b << endl; return 0; }
  • 9. Amity School of Engineering & Technology RETURN BY REFERENCE • A C++ program can be made easier to read and maintain by using references rather than pointers. A C++ function can return a reference in a similar way as it returns a pointer. • When a function returns a reference, it returns an implicit pointer to its return value. This way, a function can be used on the left side of an assignment statement. 9
  • 10. Amity School of Engineering & Technology INLINE FUNCTION • An Inline Function the programme That has requested that the compiler insert the complete body of the function in every place that the function is called, rather than generating code to call the function in the one place it is defined. 10
  • 11. Amity School of Engineering & Technology DEFAULT ARGUEMENTS • In computer programming, a default argument is an argument to a function that a programmer is not required to specify. In most programming languages, functions may take one or more arguments. • The default argument must be implicitly convertible to the parameter type. 11
  • 12. Amity School of Engineering & Technology CONSTANT ARGUEMENTS • The const variable can be declared using const keyword. • The const keyword makes variable value stable. • The constant variable should be initialized while declaring. Syntax: • (a) const <variable name> = <value>; • (b) <function name> (const <type>*<variable name>;) • (c) int const x // in valid • (d) int const x =5 // valid 12
  • 13. Amity School of Engineering & Technology RECURSION • Recursive functions: – Functions that call themselves – Can only solve a base case – Divide a problem up into • What it can do. • What it cannot do. • What it cannot do resembles • original problem. • The function launches a new copy of itself (recursion step) to solve what it cannot do 13
  • 14. Amity School of Engineering & Technology FUNCTION OVERLOADING • Function overloading is a feature found in that allows creating several methods with the same name which differ from each other in the type of the input and the output of the function. It is simply defined as the ability of one function to perform different tasks. 14
  • 15. Amity School of Engineering & Technology FRIEND & VIRTUAL FUNCTION 15 • A Friend Function access to private and protected data in that class that it would not normally be able to as if the data was public. • A Function of global or namespace scope may be declared as friend of both classes. • A Virtual Function is a function or method whose behaviour can be overridden within an inheriting class by a function with the same signature. This concept is an important part of the polymorphism portion of Object-Oriented Programming (OOP).
  • 16. Amity School of Engineering & Technology MATH LIBRARY FUNCTION • C Mathematical Operations are a group of functions in the Standard Library of the C programming language implementing basic mathematical functions. 16
  • 17. Amity School of Engineering & Technology REFERENCES • Wikipedia.com. • C++ By Yashwant Kanetkar. • C++ By E Balagurusamy. 17
  • 18. Amity School of Engineering & Technology 18