3.1. Functions

Functions group program statements into logical units. We do this to encapsulate actions that functions perform. Encapsulation is important because it separates and hides a function's programming details from its caller. With libraries of functions that provide separate compilation and linking of modules, we can call functions from anywhere in a program.

As with variables, you must define or declare functions before you call them. C++ functions have two formats. The first format is a function declaration, often called a function prototype.

					Type function_name(Type arg1, Type arg2, Type argN); 

Function prototypes give the compiler all the information it needs to verify the correctness of a function call: the function's name, its ...

Get Navigating C++ and Object-Oriented Design 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.