5. Defining Your Own Functions

The premise behind any function in any language is simple: encapsulate a process under one name. Then, by calling that name (i.e., invoking the function), you can repeat that sequence of steps with ease. You’ve already seen this in action when you use the functions defined in C++, like cin.get() or the close() function used with files. In this chapter you’ll learn how to define and call your own functions.

The syntax for defining a function is simple and consistent, but there are many permutations as to what a function can do. For starters, you’ll create a simple function, one that takes no arguments and returns no values. Then you’ll begin writing functions that take required arguments, and then those that take ...

Get C++ Programming: Visual QuickStart Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.