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
- Write functions and explain pass by value
- Follow recursion on the call stack
- Use pointers to change a caller's variables
- Pass arrays to functions
Lessons
- 1
Functions
Parameters, return values, prototypes, and why changing a parameter does not change the caller's variable.
- 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
Pointers Intermediate
Addresses with &, following them with *, NULL, and a swap function that really swaps.
- 4
Pointers and arrays Intermediate
An array name is the address of its first element, pointer arithmetic, and passing arrays to functions.
Module practice
- C: Power functionEasy
- C: Prime or not, with a functionMedium
- C: Armstrong numbersHard
- C: Digit sum by recursionEasy
- C: Fibonacci, fastMedium
- C: Binary strings with no 11Hard
- C: Swap with pointersEasy
- C: Two results through pointersMedium
- C: Division that reports failureHard
- C: Sum of an arrayEasy
- C: Reverse with two pointersMedium
- C: A pointer to the largestHard
Module quiz
‹ Decisions, loops, arrays and stringsStructures and dynamic memory ›