SlideShare a Scribd company logo
11
Most read
14
Most read
19
Most read
FUNCTIONS IN c++ PPT
Introduction
M.Nabeel Khan (61)
Daud Mirza (57)
Danish Mirza (58)
Fawad Usman (66)
Aamir Mughal (72)
M.Arslan (17)
Programming
Fundamentals
A function is a named block of code that
perform some action. The statement
written in function are executed when it is
called by its name. Each function has a
unique name. Function are the
building block of c++ programs. They are
used to perform the tasks that are
repeated many times
Importance of Function
• A program may need to repeat the same
piece of code at various places.
• It may be required to perform certain task
repeatedly.
• The program may become very large if
functions are not used.
• The real reason for using function is to
divide program into different parts.
Advantages of Functions
• Easier to Code
• Easier to Modify
• Easier to Maintain
• Reusability
• Less Programming Time
• Easier to Understand
• C++ allows the use of both internal (user-
defined) and external (Built in) functions.
• ExtErnal functions are usually
grouped into specialized libraries (e.g.,
iostream, stdlib, math, etc.)
C++ Functions
FUNCTIONS IN c++ PPT
Function Input and Output
A set of statements that explains what a
function does is called FUNCTION
Definition
A function definition can be written at:
• Before main() function
• After main() function
• In a separate file
Syntax of Function Definition
Return-type Function-name (parameters)
{
statement 1;
statement 2;
:
:
:
statement N;
}
Function header
Function body
Function Declaration
Function declaration is the model of a function. It is
also known as FUNCTION PROTOTYPE. It provides
information to compiler about the structure of
function to be used in program. It ends with
semicolon (;). It consists of:
• FUNCTION NAME
• FUNCTION RETURN TYPE
• NUMBERS & TYPES OF PARAMETERS
Syntax of Function Declaration
Return-type Function-name (parameters);
Indicates the
name of
function
Parameters are
the values that
are provided to a
function when the
function is called.
Example of Function Declaration &
Function Definition
Function Call
The statement that activates a function is
known as FUNCTION CALL.The following steps
take place when a function is called:
1.The control moves to the function that is
called.
2.All statements in function body are executed.
3. Control returns back to calling function.
Function Call Mechanism
Void main()
{
…….
Fun();
…….
…….
Fun();
…….
}
Void Fun()
{
…..
…..
}
Called
function
Calling
function
Function
calls
Example of Function Call
Scope of Functions
Area in which a function can be accessed is known
as SCOPE OF FUNCTION.
These are two types:
1.Local Function
A function that is declared in
another function is called Local Function.
1.Global Function
A function that is declared
outside any function is called Global Function.
Call by Value
• Call by value passes the
value of actual parameter to
formal parameter.
• Actual & formal parameter
refer to different memory
location.
• It requires more memory.
• It is less efficient.
Call by Reference
• Call by reference passes the
address of actual parameter
to formal parameter.
• Actual & formal parameter
refer to same memory
location.
• It requires less memory.
• It is more efficient.
Local Variable
• Local variables are declares
within a function.
• It can be used only in function
in which they declared.
• Local variable are destroyed
when control leave the
function.
• Local variables are used when
the vales are to be used within
a function.
Global Variable
• Global variables are declares
outside any function
• Global variables can be used
in all function.
• Global variable are destroyed
when the program is
terminated.
• Global variables are used
when values are to be shared
among different functions.
A program that calls a
function for five times
using loop & also using
static(local) variable.
#include <iostream>
Using namespace std;
Int fun();
Int main()
{ int I;
for( i=0;i<=5;i++)
fun();
return 0; }
Int fun()
{ static int n=0;
n++
cout<<“value of n
=“<<n<<endl;
}
A local variable declared with
keyword STATIC is called
STATIC VARIABLE. It is used to
increase the lifetime of local
variable.
•This program declare
function Fun().
•Function declare static
variable
•Initializes it to 0.
•The main() function calls five
time.
•Using FOR LOOP.
•Last statement display value
of “n”.
Register Variable
A variable declared with keyword register is
known as Register variable. The value of
register is stored in Registers instead of RAM
because Registers are faster than RAM so
value stored in Registers can be accessed
faster than RAM. Syntax for declaring is:
register data-type variable-name
Function Overloading
The process of declaring multiple functions
with same name but different parameters is
called FUNCTION OVERLOADING. The function
with same name must differ in one of the
following ways:
1.Numbers of parameters
2.Type of parameter
3.Sequence of parameters
FUNCTIONS IN c++ PPT

More Related Content

What's hot (20)

PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
PPTX
Data types in c++
Venkata.Manish Reddy
 
PPTX
Inheritance in java
RahulAnanda1
 
PPT
Control structure C++
Anil Kumar
 
PPTX
Functions in c language
tanmaymodi4
 
PPTX
Procedural programming
Ankit92Chitnavis
 
PPTX
C Programming: Control Structure
Sokngim Sa
 
PDF
Friend function in c++
University of Madras
 
PPTX
Types of Constructor in C++
Bhavik Vashi
 
PPTX
Exception Handling in object oriented programming using C++
Janki Shah
 
PPTX
Constructor in java
Pavith Gunasekara
 
PPTX
Exception handling c++
Jayant Dalvi
 
PPTX
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
PPT
Exception Handling in JAVA
SURIT DATTA
 
PPTX
Java(Polymorphism)
harsh kothari
 
PPTX
User defined functions in C
Harendra Singh
 
PPTX
Constructors and Destructor in C++
International Institute of Information Technology (I²IT)
 
PPTX
C functions
University of Potsdam
 
PPTX
Union in C programming
Kamal Acharya
 
Function in C program
Nurul Zakiah Zamri Tan
 
Data types in c++
Venkata.Manish Reddy
 
Inheritance in java
RahulAnanda1
 
Control structure C++
Anil Kumar
 
Functions in c language
tanmaymodi4
 
Procedural programming
Ankit92Chitnavis
 
C Programming: Control Structure
Sokngim Sa
 
Friend function in c++
University of Madras
 
Types of Constructor in C++
Bhavik Vashi
 
Exception Handling in object oriented programming using C++
Janki Shah
 
Constructor in java
Pavith Gunasekara
 
Exception handling c++
Jayant Dalvi
 
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
Exception Handling in JAVA
SURIT DATTA
 
Java(Polymorphism)
harsh kothari
 
User defined functions in C
Harendra Singh
 
Union in C programming
Kamal Acharya
 

Viewers also liked (20)

PPT
Functions in C++
Sachin Sharma
 
PPTX
functions of C++
tarandeep_kaur
 
PPTX
C++ programming function
Vishalini Mugunen
 
PPT
C++ Function
Hajar
 
PPTX
Functions in C++
home
 
PPT
16717 functions in C++
LPU
 
PPT
PPt on Functions
coolhanddav
 
PPTX
Function overloading
Selvin Josy Bai Somu
 
PPTX
Inline Functions and Default arguments
Nikhil Pandit
 
PPT
Functions
Online
 
PPT
Functions in C++
Mohammed Sikander
 
PPT
Functions in c++
Abdullah Turkistani
 
PPT
08 c++ Operator Overloading.ppt
Tareq Hasan
 
PPTX
Templates in C++
Tech_MX
 
PPTX
Arrays In C++
Awais Alam
 
PPTX
Function in c
Raj Tandukar
 
PDF
Function in C
Dr. Abhineet Anand
 
PPT
Intro. to prog. c++
KurdGul
 
PPTX
Presentation on overloading
Charndeep Sekhon
 
DOCX
wadi sindh وادی سندھ کی تاریخ
03062679929
 
Functions in C++
Sachin Sharma
 
functions of C++
tarandeep_kaur
 
C++ programming function
Vishalini Mugunen
 
C++ Function
Hajar
 
Functions in C++
home
 
16717 functions in C++
LPU
 
PPt on Functions
coolhanddav
 
Function overloading
Selvin Josy Bai Somu
 
Inline Functions and Default arguments
Nikhil Pandit
 
Functions
Online
 
Functions in C++
Mohammed Sikander
 
Functions in c++
Abdullah Turkistani
 
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Templates in C++
Tech_MX
 
Arrays In C++
Awais Alam
 
Function in c
Raj Tandukar
 
Function in C
Dr. Abhineet Anand
 
Intro. to prog. c++
KurdGul
 
Presentation on overloading
Charndeep Sekhon
 
wadi sindh وادی سندھ کی تاریخ
03062679929
 
Ad

Similar to FUNCTIONS IN c++ PPT (20)

PPT
Basic c++
Maria Stella Solon
 
PPT
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
PPT
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
PPTX
FUNCTION CPU
Krushal Kakadia
 
DOCX
Functions assignment
Ahmad Kamal
 
PPTX
Chapter One Function.pptx
miki304759
 
PDF
Chapter 11 Function
Deepak Singh
 
PDF
Chapter_1.__Functions_in_C++[1].pdf
TeshaleSiyum
 
PDF
Chapter 1. Functions in C++.pdf
TeshaleSiyum
 
PPTX
Function C++
Shahzad Afridi
 
PPTX
Function in c++
Kumar
 
PDF
Functions in C++.pdf
LadallaRajKumar
 
PPT
POLITEKNIK MALAYSIA
Aiman Hud
 
PPTX
Programming Methodologies Functions - C Language
ChobodiDamsaraniPadm
 
PPTX
FUNCTIONengineeringtechnologyslidesh.pptx
ricknova674
 
PPTX
Presentation on function
Abu Zaman
 
PPT
Fp201 unit5 1
rohassanie
 
PDF
Functionssssssssssssssssssssssssssss.pdf
bodzzaa21
 
PDF
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
PPTX
Function
Saniati
 
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
Chapter Introduction to Modular Programming.ppt
AmanuelZewdie4
 
FUNCTION CPU
Krushal Kakadia
 
Functions assignment
Ahmad Kamal
 
Chapter One Function.pptx
miki304759
 
Chapter 11 Function
Deepak Singh
 
Chapter_1.__Functions_in_C++[1].pdf
TeshaleSiyum
 
Chapter 1. Functions in C++.pdf
TeshaleSiyum
 
Function C++
Shahzad Afridi
 
Function in c++
Kumar
 
Functions in C++.pdf
LadallaRajKumar
 
POLITEKNIK MALAYSIA
Aiman Hud
 
Programming Methodologies Functions - C Language
ChobodiDamsaraniPadm
 
FUNCTIONengineeringtechnologyslidesh.pptx
ricknova674
 
Presentation on function
Abu Zaman
 
Fp201 unit5 1
rohassanie
 
Functionssssssssssssssssssssssssssss.pdf
bodzzaa21
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
Function
Saniati
 
Ad

More from 03062679929 (8)

PPT
DIGITAL LIBRARIES PPT
03062679929
 
PPTX
VARIETIES OF ENGLISH PPT
03062679929
 
PPT
INTEGRATION BY PARTS PPT
03062679929
 
PPT
PakISTAN & india relations IN URDU PPT BY BADSHAH
03062679929
 
PPT
035 research report writing amir
03062679929
 
PPT
Reports danish.bad
03062679929
 
PPT
informative & research report by BADSHAH
03062679929
 
PPTX
Informative &amp; research report by badshah
03062679929
 
DIGITAL LIBRARIES PPT
03062679929
 
VARIETIES OF ENGLISH PPT
03062679929
 
INTEGRATION BY PARTS PPT
03062679929
 
PakISTAN & india relations IN URDU PPT BY BADSHAH
03062679929
 
035 research report writing amir
03062679929
 
Reports danish.bad
03062679929
 
informative & research report by BADSHAH
03062679929
 
Informative &amp; research report by badshah
03062679929
 

Recently uploaded (20)

PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
epi editorial commitee meeting presentation
MIPLM
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Horarios de distribución de agua en julio
pegazohn1978
 
Difference between write and update in odoo 18
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 

FUNCTIONS IN c++ PPT

  • 2. Introduction M.Nabeel Khan (61) Daud Mirza (57) Danish Mirza (58) Fawad Usman (66) Aamir Mughal (72) M.Arslan (17)
  • 4. A function is a named block of code that perform some action. The statement written in function are executed when it is called by its name. Each function has a unique name. Function are the building block of c++ programs. They are used to perform the tasks that are repeated many times
  • 5. Importance of Function • A program may need to repeat the same piece of code at various places. • It may be required to perform certain task repeatedly. • The program may become very large if functions are not used. • The real reason for using function is to divide program into different parts.
  • 6. Advantages of Functions • Easier to Code • Easier to Modify • Easier to Maintain • Reusability • Less Programming Time • Easier to Understand
  • 7. • C++ allows the use of both internal (user- defined) and external (Built in) functions. • ExtErnal functions are usually grouped into specialized libraries (e.g., iostream, stdlib, math, etc.) C++ Functions
  • 10. A set of statements that explains what a function does is called FUNCTION Definition A function definition can be written at: • Before main() function • After main() function • In a separate file
  • 11. Syntax of Function Definition Return-type Function-name (parameters) { statement 1; statement 2; : : : statement N; } Function header Function body
  • 12. Function Declaration Function declaration is the model of a function. It is also known as FUNCTION PROTOTYPE. It provides information to compiler about the structure of function to be used in program. It ends with semicolon (;). It consists of: • FUNCTION NAME • FUNCTION RETURN TYPE • NUMBERS & TYPES OF PARAMETERS
  • 13. Syntax of Function Declaration Return-type Function-name (parameters); Indicates the name of function Parameters are the values that are provided to a function when the function is called.
  • 14. Example of Function Declaration & Function Definition
  • 15. Function Call The statement that activates a function is known as FUNCTION CALL.The following steps take place when a function is called: 1.The control moves to the function that is called. 2.All statements in function body are executed. 3. Control returns back to calling function.
  • 16. Function Call Mechanism Void main() { ……. Fun(); ……. ……. Fun(); ……. } Void Fun() { ….. ….. } Called function Calling function Function calls
  • 18. Scope of Functions Area in which a function can be accessed is known as SCOPE OF FUNCTION. These are two types: 1.Local Function A function that is declared in another function is called Local Function. 1.Global Function A function that is declared outside any function is called Global Function.
  • 19. Call by Value • Call by value passes the value of actual parameter to formal parameter. • Actual & formal parameter refer to different memory location. • It requires more memory. • It is less efficient. Call by Reference • Call by reference passes the address of actual parameter to formal parameter. • Actual & formal parameter refer to same memory location. • It requires less memory. • It is more efficient.
  • 20. Local Variable • Local variables are declares within a function. • It can be used only in function in which they declared. • Local variable are destroyed when control leave the function. • Local variables are used when the vales are to be used within a function. Global Variable • Global variables are declares outside any function • Global variables can be used in all function. • Global variable are destroyed when the program is terminated. • Global variables are used when values are to be shared among different functions.
  • 21. A program that calls a function for five times using loop & also using static(local) variable. #include <iostream> Using namespace std; Int fun(); Int main() { int I; for( i=0;i<=5;i++) fun(); return 0; } Int fun() { static int n=0; n++ cout<<“value of n =“<<n<<endl; } A local variable declared with keyword STATIC is called STATIC VARIABLE. It is used to increase the lifetime of local variable. •This program declare function Fun(). •Function declare static variable •Initializes it to 0. •The main() function calls five time. •Using FOR LOOP. •Last statement display value of “n”.
  • 22. Register Variable A variable declared with keyword register is known as Register variable. The value of register is stored in Registers instead of RAM because Registers are faster than RAM so value stored in Registers can be accessed faster than RAM. Syntax for declaring is: register data-type variable-name
  • 23. Function Overloading The process of declaring multiple functions with same name but different parameters is called FUNCTION OVERLOADING. The function with same name must differ in one of the following ways: 1.Numbers of parameters 2.Type of parameter 3.Sequence of parameters