Functions
- I. Functions
- A. The building blocks of C++
- B. A subroutine that contains one or more C++ statements and performs one or more tasks
- C. Each function has a name which is used to call it
- D. One function cannot be contained within another function, but can be called by it
- E. Types
- 1. ones created by the specific programmer
- 2. predefined functions in the Standard Library
- F. Call a function by functionname();
- G. Prototype given prior to main()
- 1. allows compiler to know function return type
- 2. allows compiler to know the number and type of parameters that function may have
- II. Function Arguments
- A. A value passed to a function
- B. Variables (parameters) that will receive the arguments of functions must be declared
- C. Argument list - comma-separated arguments of a function
- III. Functions and Values
- A. void - no value returned
- B. functions that return values
- 1. return value; - returns a value
- a. returns immediately and skips any remaining code
- 2. return type specified before definition and in prototype
- IV. The General Form of C++ Functions
- A. return-type function name (parameters)
{
body of the function
}
Back to the Main Menu