Functions and pointers

Splitting programs into functions, understanding the call stack, and using addresses to reach memory directly.

About 13 hours of study

Learning objectives

Lessons

  1. 1

    Functions

    Parameters, return values, prototypes, and why changing a parameter does not change the caller's variable.

  2. 2

    Recursion and the call stack

    Functions that call themselves: base cases, one frame per call, and what happens when there is no base case.

  3. 3

    Pointers Intermediate

    Addresses with &, following them with *, NULL, and a swap function that really swaps.

  4. 4

    Pointers and arrays Intermediate

    An array name is the address of its first element, pointer arithmetic, and passing arrays to functions.

Module practice

Module quiz

1. void f(int x) { x = 9; } After int a = 1; f(a); what is a?
2. void f(int *x) { *x = 9; } After int a = 1; f(&a); what is a?
3. Why is sizeof not useful for finding an array's length inside a function?
4. If p points to an element of an int array, what does p + 2 point to?
5. What is wrong with returning the address of a local variable?
6. What does every recursive function need?

‹ Decisions, loops, arrays and stringsStructures and dynamic memory ›