Chapter 6. Study Guide

An abstract representation of a function as a rectangle. There is only one copy of the function's instructions in the compiled program. Arrows illustrate that a function call jumps to the function's instructions while passing the function arguments to the function's parameters. Arrows also illustrate that when the function ends, control returns to the statement following the function call.

Functions and methods are a fundamental part of all major programming languages that help reduce the size of programs by eliminating redundant code. The C++ compiler translates a function body into machine instructions, stores the instructions at a specific address in memory, and saves the address in its symbol table. The compiler translates each function call into a "jump" to the function's address. The compiler also generates code to copy the function call's arguments to the compiled function's parameters. This process allows programmers to reuse a function's code, with whatever data they choose, whenever its operations are needed.

These advantages notwithstanding, the most valuable thing that functions do is help software engineers to organize a program into conceptual units. They allow engineers to think about a problem solution at a high level - they can focus on what the function does rather than how it does it. Separating "what" from "how" helps engineers manage the complexity of a program.

Furthermore, everything that we learn in the current chapter will carry over into the member functions that are a part of object-oriented programming.

Know