CH10 - An Introduction to Programming with C+, Fifth...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
An Introduction to Programming with C++, Fifth Edition 10 - 1 Chapter 10 Void Functions At a Glance Instructor’s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Topics Classroom Activities/Additional Projects Key Terms
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
An Introduction to Programming with C++, Fifth Edition 10 - 2 Lecture Notes Chapter Overview In the previous chapter, the concepts involved with a value-returning function were covered. In this chapter, the concept and implementation of a void function will be covered. In addition, the concept of passing information to a function by reference will be introduced. Contrast will also be made with value-returning vs. void functions, as well as passing by value vs. passing by reference. Chapter Objectives After completing the chapter, the student will be able to: Create and invoke a function that does not return a value Pass information, by reference, to a function Use void functions in a .NET C++ program Instructor Notes More About Functions Remember that a function is a block of code that performs a task. Every C++ program contains at least one function called main(), and most programs contain many more functions. Programmers use functions for two reasons: functions allow the programmer to avoid duplicating code in different parts of the program, and they allow large and complex programs to be broken down into small and manageable tasks. Functions are categorized as either value-returning functions or void functions. Value-returning functions return a value to the statement that called the function; whereas void functions do not return a value. Therefore, a void function will not contain a return statement at the end of its function body, as with a value-returning function. Creating Void Functions When defining a void function, you must code the function header and the function body. The function header is the first statement in the function definition. It specifies the name of the function, and any optional parameters the function may have. The following is the syntax for a void function header: void functionName([parameterList]); . Note that the rules for naming functions are the same as the rules for naming identifiers.
Background image of page 2
An Introduction to Programming with C++, Fifth Edition 10 - 3 Note the difference between the function header of a value-returning function vs. the function header of a void function. The only difference between the two is that the header in a void function begins with the keyword void, where the header in a value-returning function begins with the return data type of the function. After coding the function header, the function body must be coded. The function body will
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2010 for the course CS 343 taught by Professor Katzman during the Spring '09 term at ITT Tech Tucson.

Page1 / 6

CH10 - An Introduction to Programming with C+, Fifth...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online