Module 3 - Functions 1: Making our code more modular | GDB and FunctionsModule Overview
1.) C++ is not the C Language -- Course Introduction
2.) C++ Batteries Included - STL and GDB Debugging with the STL
3.) Functions 1: Making our code more modular | GDB and Functions
4.) Input and Output
5.) C++: Thinking about memory
6.) Memory Allocation and Layout
7.) Arrays, Splines, and SFML Library Introduction
8.) Building Data Structures -- Structs and Linked Lists
9.) Physical Structure of a C++ Project
10.) No Class
11.) Graphics Applications, Textures, Images, Sprites, and 2D Arrays
12.) Object-Oriented Programming 1
13.) Object-Oriented Programming 2
14.) Object-Oriented Programming 3 - Composition & Inheritance
15.) Binary Tree Data Structure
16.) C++ Templates - Code Generation and Generics
17.) Smart Pointers and Quad Trees
18.) Iterators and Algorithms
19.) Concurrency and Threading
20.) Final Project Discussion
21.) Review/Functors/Lambda's/
22.) Graphs
23.) Holiday no class
24.) LValues, RValues, and Move Semantics
25.) Advanced Topic 1 - Scripting with C++ using Pybind11 and Lua
☰ Select another Module

Audio/Video Recording

...Commented Code Samples (if any)

For now I am linking code samples here: Github Code Repository for the course

Additional Resources


(Graded) In-Class Activity link

  • In-Class Activity Link
    • This is graded, and only your first response is graded
    • This is an evaluation of what was learned in lecture.
    • Due one week from when the lecture takes place

Module Content

Module Overview

In this module we learn about functions!

Module Outline

  • Lecture outline
    • Pass by Value
    • Pass by Reference
    • const parameters
    • constexpr parameters
    • Function polymorphism
    • Small math library
    • Using GDB to debug functions


(Optional Notes)


Functions in the C++ programming language are like

Some languages use other terminology for functions. e.g. Pascal has 'procedures' along with functions for example, and other languages use the terminology 'subroutine'. While languages may also offer slightly different semantics to how these different keywords are used, the idea of breaking a program into smaller 'routines' can help make programs more understandable.

The anatomy of a function

  • Return Value
  • Name of the function

Function Overloading

Function overloading is a type of 'polymorphism'. Polymorphism means 'many forms'.


// Example function that can add integers
int add(int a, int b){
    return a+b;

// Example function that can add floating point numbers
float add(float a, float b){
    return a+b;

// Example function that can add two std::string 
// Note: We would probably better call this 'concatenate', but
//       I think you get the idea. Also, we'll have to look into
//       'overloading the +' operator to handle the rules of
//       what it means to add two strings together.
std::string add(std::string, std::string){
    return a+b;


C++ functions support recursion as you may have seen in other functions.

Recursive Function Pattern

  1. Base Case
  2. Recursive Function Call

Function Calling Conventions

Call by Value

Historically this was called 'call by copy' or 'call by copy restore' which may be a slightly more realistic name.

Call by Reference

Pass in parameters by 'reference'. Can think of a 'reference' as an alias, in other words, it's something that already exists and we can make use of.

Function Call Stack

Talk about how the function call stack works

Please do not redistribute or host any materials without e-mailing me first. I generally am happy to share the latest .pdf or slide presentation with those who ask. Thank you for your time!