Chp5 - C+ PROGRAMMING Chapter 5 Functions What Is a...

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

View Full Document Right Arrow Icon
C++ PROGRAMMING Chapter 5 Functions What Is a Function? Figure 5.1. Declaring and Defining Functions Declaring the Function Function Prototypes & Figure 5.2. Listing 5.1. A function declaration and the definition and use of that function. Defining the Function & Figure 5.3. Functions Execution of Functions Local Variables Listing 5.2. The use of local variables and parameters . Global Variables Listing 5.3. Demonstrating global and local variables . Global Variables: A Word of Caution More on Local Variables Listing 5.4. Variables scoped within a block . Function Statements & Function Arguments Using Functions as Parameters to Functions Parameters Are Local Variables Listing 5.5. A demonstration of passing by value . Return Values Listing 5.6. A demonstration of multiple return statements . Default Parameters Listing 5.7. A demonstration of default parameter values. Overloading Functions Listing 5.8. A demonstration of function polymorphism . Special Topics About Functions Inline Functions Listing 5.9. Demonstrates an inline function . Recursion Listing 5.10. Demonstrates recursion using the Fibonacci series . How Functions WorkA Look Under the Hood Levels of Abstraction , Partitioning RAM Figure 5.4. , Figure 5.5. , Figure 5.6. & Figure 5.7. The Stack and Functions Summary Quiz , Exercises
Background image of page 1

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

View Full DocumentRight Arrow Icon
Chapter 5 Functions Although object-oriented programming has shifted attention from functions and toward objects, functions nonetheless remain a central component of any program. ToChapter you will learn What a function is and what its parts are. How to declare and define functions. How to pass parameters into functions. How to return a value from a function. What Is a Function? A function is, in effect, a subprogram that can act on data and return a value. Every C++ program has at least one function, main() . When your program starts, main() is called automatically. main() might call other functions, some of which might call still others. Each function has its own name, and when that name is encountered, the execution of the program branches to the body of that function. When the function returns, execution resumes on the next line of the calling function. This flow is illustrated in Figure 5.1. Figure 5.1. Illusrtation of flow When a program calls a function, execution switches to the function and then resumes at the line after the function call. Well-designed functions perform a specific and easily understood task. Complicated tasks should be broken down into multiple functions, and then each can be called in turn. Functions come in two varieties: user-defined and built-in. Built-in functions are part of
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2012 for the course CS 131 taught by Professor Clayton during the Spring '08 term at Bethune Cookman.

Page1 / 32

Chp5 - C+ PROGRAMMING Chapter 5 Functions What Is a...

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

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