SlideShare a Scribd company logo
1 of 18
Introduction to Programming in C++
Eight Edition
Lesson 10: Void Functions
An Introduction to Programming with C++, Eight Edition
• Create a void function
• Invoke a void function
• Pass information by reference to a function
Objectives
2
An Introduction to Programming with C++, Eight Edition
• Recall that value-returning functions perform a task and
then return a single value
• Void functions also perform tasks but do not return a
value
• A void function may be used to do something like
display information on the screen
– Doesn’t need to return a value
Functions
3
An Introduction to Programming with C++, Eight Edition 4
Figure 10-2 How to create a program-defined void function
Creating Program-Defined Void
Functions
An Introduction to Programming with C++, Eight Edition
• Note that header begins with keyword void, instead of
a return data type
– Indicates that the function does not return a value
• Function body does not contain a return statement
• Call a void function by including its name and actual
arguments (if any) in a statement
• Call to a void function appears as a self-contained
statement, not part of another statement
• Execution is same as for value-returning functions
Creating Program-Defined Void
Functions (cont’d.)
5
An Introduction to Programming with C++, Eight Edition 6
Figure 10-4 IPO chart information and C++
instructions for the ABC Company program
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition 7
Figure 10-4 IPO chart information and C++
instructions for the ABC Company program (cont’d.)
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition 8
Figure 10-4 IPO chart information and C++
instructions for the ABC Company program (cont’d.)
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition 9
Figure 10-4 IPO chart information and C++
instructions for the ABC Company program (cont’d.)
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition 10
Figure 10-4 IPO chart information and C++
instructions for the ABC Company program (cont’d.)
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition 11
Figure 10-5 ABC Company program
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition 12
Figure 10-5 ABC Company program (cont’d.)
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition 13
Figure 10-6 Sample run of the ABC Company program
Creating Program-Defined Void
Functions (cont’d.)
An Introduction to Programming with C++, Eight Edition
• Recall you can pass a variable’s value or its address
• Passing a variable’s value is referred to as passing by
value, while passing a variable’s address is referred to as
passing by reference
• Which one you choose depends on whether the receiving
function should have access to the variable in memory
• Passing by value will not permit the function to change
the contents of the variable, but passing by reference will
Passing Variables to a Function
14
An Introduction to Programming with C++, Eight Edition
• Passing a variable by value means that only a copy of
the variable’s contents is passed, not the address of the
variable
• This means that the receiving function cannot change
the contents of the variable
• It is thus appropriate to pass by value when the
receiving function needs to know the value of the
variable but does not need to change it
Reviewing Passing Variables by Value
15
An Introduction to Programming with C++, Eight Edition
• Passing a variable’s address in internal memory to a
function is referred to as passing by reference
• You pass by reference when you want the receiving
function to change the contents of the variable
• To pass by reference in C++, you include an ampersand
(&) before the name of the formal parameter in the
receiving function’s header
• Ampersand (&) is the address-of operator
– Tells the computer to pass the variable’s address rather
than a copy of its contents
Passing Variables by Reference
16
An Introduction to Programming with C++, Eight Edition
• If receiving function appears below main, you must
also include the & in the receiving function’s prototype
• You enter the & immediately before the name of the
formal parameter in the prototype
– If the prototype does not contain the formal parameter’s
name, you enter a space followed by & after the formal
parameter’s data type
• Void functions use variables passed by reference to
send information back to the calling function, instead of
a return value
Passing Variables by Reference
(cont’d.)
17
An Introduction to Programming with C++, Eight Edition 18
Figure 10-13 Modified age message program
Passing Variables by Reference
(cont’d.)

More Related Content

What's hot

test(3)arithmetic in c
test(3)arithmetic in ctest(3)arithmetic in c
test(3)arithmetic in cJaya Malathy
 
Programming in c (importance of c)
Programming in c (importance of c)Programming in c (importance of c)
Programming in c (importance of c)ViswanathanS21
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10Jadavsejal
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14IIUM
 
Software Engineer Screening Question - OOP
Software Engineer Screening Question - OOPSoftware Engineer Screening Question - OOP
Software Engineer Screening Question - OOPjason_scorebig
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...vtunotesbysree
 
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...Publicis Sapient Engineering
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Soham Kulkarni
 
Let’s Build a Python Profiler in 25 LOC
Let’s Build a Python Profiler in 25 LOCLet’s Build a Python Profiler in 25 LOC
Let’s Build a Python Profiler in 25 LOCNoam Elfanbaum
 

What's hot (20)

Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
 
Lesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th stepLesson 4.2 5th and 6th step
Lesson 4.2 5th and 6th step
 
Lesson 3.1 variables and constant
Lesson 3.1 variables and constantLesson 3.1 variables and constant
Lesson 3.1 variables and constant
 
Lesson 5 .1 selection structure
Lesson 5 .1 selection structureLesson 5 .1 selection structure
Lesson 5 .1 selection structure
 
Lesson 13 object and class
Lesson 13 object and classLesson 13 object and class
Lesson 13 object and class
 
Lesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving processLesson 2 beginning the problem solving process
Lesson 2 beginning the problem solving process
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 
test(3)arithmetic in c
test(3)arithmetic in ctest(3)arithmetic in c
test(3)arithmetic in c
 
Lesson 3.2 data types for memory location
Lesson 3.2 data types for memory locationLesson 3.2 data types for memory location
Lesson 3.2 data types for memory location
 
Programming in c (importance of c)
Programming in c (importance of c)Programming in c (importance of c)
Programming in c (importance of c)
 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14Csc1100 lecture03 ch03-pt2-s14
Csc1100 lecture03 ch03-pt2-s14
 
C Program Structure
C Program StructureC Program Structure
C Program Structure
 
Software Engineer Screening Question - OOP
Software Engineer Screening Question - OOPSoftware Engineer Screening Question - OOP
Software Engineer Screening Question - OOP
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
 
Compiler Construction for DLX Processor
Compiler Construction for DLX Processor Compiler Construction for DLX Processor
Compiler Construction for DLX Processor
 
Let’s Build a Python Profiler in 25 LOC
Let’s Build a Python Profiler in 25 LOCLet’s Build a Python Profiler in 25 LOC
Let’s Build a Python Profiler in 25 LOC
 

Similar to C++ void functions lesson

Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdfziyadaslanbey
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptManivannan837728
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfmadihamaqbool6
 
Chapter 5 - Modular Programming.pdf
Chapter 5 - Modular Programming.pdfChapter 5 - Modular Programming.pdf
Chapter 5 - Modular Programming.pdfKirubelWondwoson1
 
Chapter 6 - Modular Programming- in C++.pptx
Chapter 6 - Modular Programming- in C++.pptxChapter 6 - Modular Programming- in C++.pptx
Chapter 6 - Modular Programming- in C++.pptxChereLemma2
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06Terry Yoast
 
OOP in C++
OOP in C++OOP in C++
OOP in C++ppd1961
 
Functions in c++
Functions in c++Functions in c++
Functions in c++Asaye Dilbo
 
Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...Sar
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in Cbhawna kol
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFaisal Shehzad
 
Functions in C++ programming language.pptx
Functions in  C++ programming language.pptxFunctions in  C++ programming language.pptx
Functions in C++ programming language.pptxrebin5725
 
9781285852744 ppt ch13
9781285852744 ppt ch139781285852744 ppt ch13
9781285852744 ppt ch13Terry Yoast
 

Similar to C++ void functions lesson (20)

Presentation 2.pptx
Presentation 2.pptxPresentation 2.pptx
Presentation 2.pptx
 
Presentation 2 (1).pdf
Presentation 2 (1).pdfPresentation 2 (1).pdf
Presentation 2 (1).pdf
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
U19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).pptU19CS101 - PPS Unit 4 PPT (1).ppt
U19CS101 - PPS Unit 4 PPT (1).ppt
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 
Chapter 5 - Modular Programming.pdf
Chapter 5 - Modular Programming.pdfChapter 5 - Modular Programming.pdf
Chapter 5 - Modular Programming.pdf
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Chapter 6 - Modular Programming- in C++.pptx
Chapter 6 - Modular Programming- in C++.pptxChapter 6 - Modular Programming- in C++.pptx
Chapter 6 - Modular Programming- in C++.pptx
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
Rcpp
RcppRcpp
Rcpp
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...Functions in c++, presentation, short and sweet presentation, and details of ...
Functions in c++, presentation, short and sweet presentation, and details of ...
 
Modular Programming in C
Modular Programming in CModular Programming in C
Modular Programming in C
 
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal ShahzadFunction Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
Function Overloading,Inline Function and Recursion in C++ By Faisal Shahzad
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Functions in C++ programming language.pptx
Functions in  C++ programming language.pptxFunctions in  C++ programming language.pptx
Functions in C++ programming language.pptx
 
9781285852744 ppt ch13
9781285852744 ppt ch139781285852744 ppt ch13
9781285852744 ppt ch13
 

More from MLG College of Learning, Inc (20)

PC111.Lesson2
PC111.Lesson2PC111.Lesson2
PC111.Lesson2
 
PC111.Lesson1
PC111.Lesson1PC111.Lesson1
PC111.Lesson1
 
PC111-lesson1.pptx
PC111-lesson1.pptxPC111-lesson1.pptx
PC111-lesson1.pptx
 
PC LEESOON 6.pptx
PC LEESOON 6.pptxPC LEESOON 6.pptx
PC LEESOON 6.pptx
 
PC 106 PPT-09.pptx
PC 106 PPT-09.pptxPC 106 PPT-09.pptx
PC 106 PPT-09.pptx
 
PC 106 PPT-07
PC 106 PPT-07PC 106 PPT-07
PC 106 PPT-07
 
PC 106 PPT-01
PC 106 PPT-01PC 106 PPT-01
PC 106 PPT-01
 
PC 106 PPT-06
PC 106 PPT-06PC 106 PPT-06
PC 106 PPT-06
 
PC 106 PPT-05
PC 106 PPT-05PC 106 PPT-05
PC 106 PPT-05
 
PC 106 Slide 04
PC 106 Slide 04PC 106 Slide 04
PC 106 Slide 04
 
PC 106 Slide no.02
PC 106 Slide no.02PC 106 Slide no.02
PC 106 Slide no.02
 
pc-106-slide-3
pc-106-slide-3pc-106-slide-3
pc-106-slide-3
 
PC 106 Slide 2
PC 106 Slide 2PC 106 Slide 2
PC 106 Slide 2
 
PC 106 Slide 1.pptx
PC 106 Slide 1.pptxPC 106 Slide 1.pptx
PC 106 Slide 1.pptx
 
Db2 characteristics of db ms
Db2 characteristics of db msDb2 characteristics of db ms
Db2 characteristics of db ms
 
Db1 introduction
Db1 introductionDb1 introduction
Db1 introduction
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 
Lesson 3.1
Lesson 3.1Lesson 3.1
Lesson 3.1
 
Lesson 1.6
Lesson 1.6Lesson 1.6
Lesson 1.6
 
Lesson 3.2
Lesson 3.2Lesson 3.2
Lesson 3.2
 

Recently uploaded

Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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 ConsultingTechSoup
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
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 ModeThiyagu K
 

Recently uploaded (20)

Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
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
 

C++ void functions lesson

  • 1. Introduction to Programming in C++ Eight Edition Lesson 10: Void Functions
  • 2. An Introduction to Programming with C++, Eight Edition • Create a void function • Invoke a void function • Pass information by reference to a function Objectives 2
  • 3. An Introduction to Programming with C++, Eight Edition • Recall that value-returning functions perform a task and then return a single value • Void functions also perform tasks but do not return a value • A void function may be used to do something like display information on the screen – Doesn’t need to return a value Functions 3
  • 4. An Introduction to Programming with C++, Eight Edition 4 Figure 10-2 How to create a program-defined void function Creating Program-Defined Void Functions
  • 5. An Introduction to Programming with C++, Eight Edition • Note that header begins with keyword void, instead of a return data type – Indicates that the function does not return a value • Function body does not contain a return statement • Call a void function by including its name and actual arguments (if any) in a statement • Call to a void function appears as a self-contained statement, not part of another statement • Execution is same as for value-returning functions Creating Program-Defined Void Functions (cont’d.) 5
  • 6. An Introduction to Programming with C++, Eight Edition 6 Figure 10-4 IPO chart information and C++ instructions for the ABC Company program Creating Program-Defined Void Functions (cont’d.)
  • 7. An Introduction to Programming with C++, Eight Edition 7 Figure 10-4 IPO chart information and C++ instructions for the ABC Company program (cont’d.) Creating Program-Defined Void Functions (cont’d.)
  • 8. An Introduction to Programming with C++, Eight Edition 8 Figure 10-4 IPO chart information and C++ instructions for the ABC Company program (cont’d.) Creating Program-Defined Void Functions (cont’d.)
  • 9. An Introduction to Programming with C++, Eight Edition 9 Figure 10-4 IPO chart information and C++ instructions for the ABC Company program (cont’d.) Creating Program-Defined Void Functions (cont’d.)
  • 10. An Introduction to Programming with C++, Eight Edition 10 Figure 10-4 IPO chart information and C++ instructions for the ABC Company program (cont’d.) Creating Program-Defined Void Functions (cont’d.)
  • 11. An Introduction to Programming with C++, Eight Edition 11 Figure 10-5 ABC Company program Creating Program-Defined Void Functions (cont’d.)
  • 12. An Introduction to Programming with C++, Eight Edition 12 Figure 10-5 ABC Company program (cont’d.) Creating Program-Defined Void Functions (cont’d.)
  • 13. An Introduction to Programming with C++, Eight Edition 13 Figure 10-6 Sample run of the ABC Company program Creating Program-Defined Void Functions (cont’d.)
  • 14. An Introduction to Programming with C++, Eight Edition • Recall you can pass a variable’s value or its address • Passing a variable’s value is referred to as passing by value, while passing a variable’s address is referred to as passing by reference • Which one you choose depends on whether the receiving function should have access to the variable in memory • Passing by value will not permit the function to change the contents of the variable, but passing by reference will Passing Variables to a Function 14
  • 15. An Introduction to Programming with C++, Eight Edition • Passing a variable by value means that only a copy of the variable’s contents is passed, not the address of the variable • This means that the receiving function cannot change the contents of the variable • It is thus appropriate to pass by value when the receiving function needs to know the value of the variable but does not need to change it Reviewing Passing Variables by Value 15
  • 16. An Introduction to Programming with C++, Eight Edition • Passing a variable’s address in internal memory to a function is referred to as passing by reference • You pass by reference when you want the receiving function to change the contents of the variable • To pass by reference in C++, you include an ampersand (&) before the name of the formal parameter in the receiving function’s header • Ampersand (&) is the address-of operator – Tells the computer to pass the variable’s address rather than a copy of its contents Passing Variables by Reference 16
  • 17. An Introduction to Programming with C++, Eight Edition • If receiving function appears below main, you must also include the & in the receiving function’s prototype • You enter the & immediately before the name of the formal parameter in the prototype – If the prototype does not contain the formal parameter’s name, you enter a space followed by & after the formal parameter’s data type • Void functions use variables passed by reference to send information back to the calling function, instead of a return value Passing Variables by Reference (cont’d.) 17
  • 18. An Introduction to Programming with C++, Eight Edition 18 Figure 10-13 Modified age message program Passing Variables by Reference (cont’d.)