Ch6: Functions
Overview
This chapter introduces one of the most important concepts in all of C++:
functions. Functions allow you to group code into reusable,
meaningful units. Every program you have written so far already uses
functions such as main, ::fast_io::println,
and the constructors of containers.
In this chapter, you will learn:
- how to define your own functions
- how parameters and return values work
- the difference between declarations and definitions
- how arguments are passed (by value, by reference, by const reference)
- how function overloading works
- how default arguments work
- how to write
inlineandconstexprfunctions - how function pointers work
- an introduction to lambda expressions
A major goal of this chapter is to show how functions help you structure programs, reduce duplication, and express intent clearly. Functions are the foundation of all higher‑level abstractions in C++, including classes, templates, and algorithms.
Contents
- Ch6.1: What is a Function?
- Ch6.2: Declarations and Definitions
- Ch6.3: Passing Arguments
- Ch6.4: Returning Values
- Ch6.5: Default Arguments
- Ch6.6: Function Overloading
- Ch6.7: Translation Units
- Ch6.8: inline
- Ch6.9: C‑Style Array Parameters
- Ch6.10: fast_io views
- Ch6.11: Recursion
- Ch6.12: Function Pointers
- Ch6.13: Lambdas
- Ch6.14: Higher‑Order Functions
- Ch6.15: Best Practices