Lesson 7. Organizing Code with Functions

So far in this book you have seen simple programs where all programming effort is contained in main(). This works very well for really small programs and applications. The larger and more complex your program gets, the longer the contents of main() becomes, unless you choose to structure your program using functions.

Functions give you a way to compartmentalize and organize your program’s execution logic. They enable you to split the contents of your application into logical blocks that are invoked sequentially.

A function is hence a subprogram that optionally takes parameters and returns a value, and it needs to be invoked to perform its task. In this lesson you learn

• The need for programming functions ...

Get Sams Teach Yourself C++ in One Hour a Day, Seventh 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.