Overview

We’ve been avoiding talking much about those weird * that show up in various places in C, but now it’s time to dive in to one of the most powerful but feared features of C: pointers! This is one of the aspects of C that makes it a “lower level” language, since pointers give you much more control and access, but come with additional complexity and responsibility.

Basic Learning Objectives

Before class, you should be able to:

  • Explain the difference between int and int *
  • Explain the general idea of pointers
  • Identify some of the benefits of using pointers

Advanced Learning Objectives

After class, you should be able to:

  • Correctly use * and & operators
  • Explain the benefits and reasons to use pointers

Resources

You should read/watch the following (if you aren’t a fan of goofy videos, you can skip the first one):

Checks

Submit answers to the following on Moodle:

  1. Given a variable int count=5, what is the C code to define a variable count_ptr that holds the memory address of count?

  2. Complete the following code that swaps the values stored at two char pointers:

There are a lot more exercises on DIS if you’d like more practice: