Chapter 12

Dividing Programs into Modules

In This Chapter

arrow Breaking programs down into functions

arrow Writing and using functions

arrow Returning values from a function

arrow Passing values to a function

arrow Providing a function prototype declaration

In Chapter 11, I show you how to divide a complex problem into a number of separate functions; it is much easier to write and get a number of smaller functions to work than one large, monolithic program. Often, however, you may want to reuse the functions you create in other applications. For example, I could imagine reusing the factorial() function created in Chapter 11.

One way to reuse such functions is to copy-and-paste the source code for the factorial() function into my new program. However, it would be a lot easier if I could put the function in a separate file that I could then link into future applications. Breaking programs into separate source code modules is the subject of this chapter.

Breaking Programs Apart

The programmer can break a single ...

Get Beginning Programming with C++ For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.