|
|
|
|
|
|
|
When people talk about C++ they mention objects first. Yet objects rely on functions to get their work done. Today 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 |
|
|
|
|
|
|
|
|
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. |
|
|
|
|
|