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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access