Learn C With Me #03 — Functions & Passing by Value | Live

In Lesson 3 of Learn C With Me, we dive into one of the fundamental building blocks of C programming: functions.

Using Beej’s Guide to C as our study material, we learn how functions accept arguments, return values, and interact with variables in the rest of our program.

We cover:

  • Defining and calling functions
  • Function parameters and arguments
  • Function return types
  • Using void for functions with no parameters or return value
  • Local variables inside functions
  • Passing arguments by value
  • Why modifying a function parameter doesn’t modify the original variable
  • Function prototypes
  • Declaring functions before using them
  • Implicit function declarations
  • How header files provide function prototypes
  • Empty parameter lists
  • Differences between older C standards and C23
  • Compiling with GCC using stricter warnings and -pedantic

We spend some extra time experimenting with pass-by-value to understand why changing a parameter inside a function doesn’t change the variable that was passed to it. Rather than just accepting the rule, we compile and run the code and work through what actually happens to the values.

We also compare older C behavior with C23, particularly around empty parameter lists and the use of void.

After finishing the main lesson, we tackle some FizzBuzz homework from the previous stream. The challenge is to replace the original if/else solution with ternary operators, gradually breaking the problem into smaller pieces and building it back into a compact solution.