Skip to main content

13.1) Basic Principles


Functions are one of two key features in C++ that support a structured approach to programming, the other being classes (covered briefly later).

Note that some languages (e.g., Ada & Fortran) distinguish between functions, which return a value to their caller just like mathematical functions, and subroutines or procedures, which don't return a value and are therefore called merely for side-effects such as displaying output. C++ has only functions, which can return a value or not return a value, as desired.

As in all such languages, the benefits of using functions are threefold: they reduce the repetition of code; they modularize code so that it can be reused more intelligently, without the need to copy and paste lines from one program into another; and they provide an abstraction mechanism, allowing us to hide the details of how a particular task is performed from anyone who isn't interested in those details.