SlideShare ist ein Scribd-Unternehmen logo
1 von 24
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
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

Weitere ähnliche Inhalte

Was ist angesagt?

Inline function
Inline functionInline function
Inline function
Tech_MX
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
Abhilash Nair
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 

Was ist angesagt? (20)

Inline function
Inline functionInline function
Inline function
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Loops c++
Loops c++Loops c++
Loops c++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function in c
Function in cFunction in c
Function in c
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
C functions
C functionsC functions
C functions
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Call by value
Call by valueCall by value
Call by value
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
This pointer
This pointerThis pointer
This pointer
 

Andere mochten auch

C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
PPt on Functions
PPt on FunctionsPPt on Functions
PPt on Functions
coolhanddav
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
Charndeep Sekhon
 
wadi sindh وادی سندھ کی تاریخ
wadi sindh وادی سندھ کی تاریخwadi sindh وادی سندھ کی تاریخ
wadi sindh وادی سندھ کی تاریخ
03062679929
 

Andere mochten auch (20)

functions of C++
functions of C++functions of C++
functions of C++
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
PPt on Functions
PPt on FunctionsPPt on Functions
PPt on Functions
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 
Functions
FunctionsFunctions
Functions
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Function in c
Function in cFunction in c
Function in c
 
Function in C
Function in CFunction in C
Function in C
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
 
wadi sindh وادی سندھ کی تاریخ
wadi sindh وادی سندھ کی تاریخwadi sindh وادی سندھ کی تاریخ
wadi sindh وادی سندھ کی تاریخ
 
Informative &amp; research report by badshah
Informative &amp; research report by badshahInformative &amp; research report by badshah
Informative &amp; research report by badshah
 

Ähnlich wie FUNCTIONS IN c++ PPT

662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
ManiMala75
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
Deepak Singh
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
sarthakgithub
 

Ähnlich wie FUNCTIONS IN c++ PPT (20)

Basic c++
Basic c++Basic c++
Basic c++
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
662213141-Tuxdoc-com-Programming-in-c-Reema-Thareja.pdf
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptx
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.ppt
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
Functions
FunctionsFunctions
Functions
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptx
 
Functions_new.pptx
Functions_new.pptxFunctions_new.pptx
Functions_new.pptx
 
Function
Function Function
Function
 
OOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptxOOP-Module-1-Section-4-LectureNo1-5.pptx
OOP-Module-1-Section-4-LectureNo1-5.pptx
 
ch-3 funtions - 1 class 12.pdf
ch-3 funtions - 1 class 12.pdfch-3 funtions - 1 class 12.pdf
ch-3 funtions - 1 class 12.pdf
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
User defined functions.1
User defined functions.1User defined functions.1
User defined functions.1
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptx
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptx
 

Mehr von 03062679929 (7)

DIGITAL LIBRARIES PPT
DIGITAL LIBRARIES PPT DIGITAL LIBRARIES PPT
DIGITAL LIBRARIES PPT
 
VARIETIES OF ENGLISH PPT
VARIETIES OF ENGLISH PPTVARIETIES OF ENGLISH PPT
VARIETIES OF ENGLISH PPT
 
INTEGRATION BY PARTS PPT
INTEGRATION BY PARTS PPT INTEGRATION BY PARTS PPT
INTEGRATION BY PARTS PPT
 
PakISTAN & india relations IN URDU PPT BY BADSHAH
PakISTAN & india relations IN URDU PPT BY BADSHAHPakISTAN & india relations IN URDU PPT BY BADSHAH
PakISTAN & india relations IN URDU PPT BY BADSHAH
 
035 research report writing amir
035 research report writing amir035 research report writing amir
035 research report writing amir
 
Reports danish.bad
Reports danish.badReports danish.bad
Reports danish.bad
 
informative & research report by BADSHAH
informative & research report by BADSHAHinformative & research report by BADSHAH
informative & research report by BADSHAH
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

FUNCTIONS IN c++ PPT

  • 1.
  • 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
  • 8.
  • 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