Chapter 6. Organizing Code with Functions

Although object-oriented programming has shifted attention from functions and toward objects, functions nonetheless remain a central component of any program. Global functions can exist outside of objects and classes, and member functions (sometimes called member methods) exist within a class and do its work.

In this lesson, you will learn

  • What a function is and what its parts are

  • How to declare and define functions

  • How to pass parameters into functions

  • How to return a value from a function

You’ll start with global functions in this lesson, and in Lesson 10, “Classes and Objects,” you’ll see how functions work from within classes and objects as well.

What Is a Function?

A function is, in effect, a subprogram that ...

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