Chapter 2

Functions

Lesson Objectives

By the end of this chapter, you will be able to:

  • Explain what functions are and how to declare them
  • Utilize local and global variables
  • Pass arguments to functions and return values from functions
  • Create overloaded functions and call them appropriately
  • Apply the concept of namespaces in organizing functions

In this chapter, we are going to look at functions in C++, how to use them, and why we would want to use them.

Introduction

Functions are a core tool in a programmer's toolkit for writing maintainable code. The concept of a function is common in almost every programming language. Functions have different names in various languages: procedures, routines, and many more, but they all have two ...

Get C++ Fundamentals 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.