SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances (20)

Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Inline function
Inline functionInline function
Inline function
 
functions of C++
functions of C++functions of C++
functions of C++
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Storage class in C Language
Storage class in C LanguageStorage class in C Language
Storage class in C Language
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 

En vedette

C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++LPU
 
PPt on Functions
PPt on FunctionsPPt on Functions
PPt on Functionscoolhanddav
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default argumentsNikhil Pandit
 
Functions
FunctionsFunctions
FunctionsOnline
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.pptTareq Hasan
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++KurdGul
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading Charndeep Sekhon
 
wadi sindh وادی سندھ کی تاریخ
wadi sindh وادی سندھ کی تاریخwadi sindh وادی سندھ کی تاریخ
wadi sindh وادی سندھ کی تاریخ03062679929
 
Informative &amp; research report by badshah
Informative &amp; research report by badshahInformative &amp; research report by badshah
Informative &amp; research report by badshah03062679929
 
Reports danish.bad
Reports danish.badReports danish.bad
Reports danish.bad03062679929
 

En vedette (20)

Functions in C++
Functions in C++Functions in C++
Functions in 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
 
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
 
Reports danish.bad
Reports danish.badReports danish.bad
Reports danish.bad
 

Similaire à FUNCTIONS IN c++ PPT

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-2sumitbardhan
 
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.pdfManiMala75
 
Lecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxLecture 1_Functions in C.pptx
Lecture 1_Functions in C.pptxKhurramKhan173
 
Chapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptChapter Introduction to Modular Programming.ppt
Chapter Introduction to Modular Programming.pptAmanuelZewdie4
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 FunctionDeepak Singh
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C ProgrammingAnil Pokhrel
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
CHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxCHAPTER THREE FUNCTION.pptx
CHAPTER THREE FUNCTION.pptxGebruGetachew2
 
Functions_new.pptx
Functions_new.pptxFunctions_new.pptx
Functions_new.pptxYagna15
 
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.pptxsarthakgithub
 
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.pdfzafar578075
 
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)Mansi Tyagi
 
CH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxCH.4FUNCTIONS IN C (1).pptx
CH.4FUNCTIONS IN C (1).pptxsangeeta borde
 
FUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxFUNCTIONS IN C.pptx
FUNCTIONS IN C.pptxSKUP1
 

Similaire à 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
 

Plus de 03062679929

DIGITAL LIBRARIES PPT
DIGITAL LIBRARIES PPT DIGITAL LIBRARIES PPT
DIGITAL LIBRARIES PPT 03062679929
 
VARIETIES OF ENGLISH PPT
VARIETIES OF ENGLISH PPTVARIETIES OF ENGLISH PPT
VARIETIES OF ENGLISH PPT03062679929
 
INTEGRATION BY PARTS PPT
INTEGRATION BY PARTS PPT INTEGRATION BY PARTS PPT
INTEGRATION BY PARTS PPT 03062679929
 
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 BADSHAH03062679929
 
035 research report writing amir
035 research report writing amir035 research report writing amir
035 research report writing amir03062679929
 
informative & research report by BADSHAH
informative & research report by BADSHAHinformative & research report by BADSHAH
informative & research report by BADSHAH03062679929
 

Plus de 03062679929 (6)

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
 
informative & research report by BADSHAH
informative & research report by BADSHAHinformative & research report by BADSHAH
informative & research report by BADSHAH
 

Dernier

M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxEduSkills OECD
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxKatherine Villaluna
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesCeline George
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17Celine George
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 
Philosophy of Education and Educational Philosophy
Philosophy of Education  and Educational PhilosophyPhilosophy of Education  and Educational Philosophy
Philosophy of Education and Educational PhilosophyShuvankar Madhu
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfTechSoup
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17Celine George
 

Dernier (20)

Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptx
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
How to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 SalesHow to Manage Cross-Selling in Odoo 17 Sales
How to Manage Cross-Selling in Odoo 17 Sales
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 
Philosophy of Education and Educational Philosophy
Philosophy of Education  and Educational PhilosophyPhilosophy of Education  and Educational Philosophy
Philosophy of Education and Educational Philosophy
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdfPersonal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024UKCGE Parental Leave Discussion March 2024
UKCGE Parental Leave Discussion March 2024
 
How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17How to Make a Field read-only in Odoo 17
How to Make a Field read-only in Odoo 17
 

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