To be an expert C programmer you need to master the use of pointers. This course explains pointers in real depth. It explains pointer variables, pointer arithmetic, indirection, memory allocation, how to create and maintain linked lists and how to use function pointers. In fact, by the time you finish this course, you will know pointers inside out. You will understand what they are, how they work and how to make sure that they don’t make your programs crash.
To be an expert C programmer you need to master the use of pointers. This course explains pointers in real depth. It explains pointer variables, pointer arithmetic, indirection, memory allocation, how to create and maintain linked lists and how to use function pointers. In fact, by the time you finish this course, you will know pointers inside out. You will understand what they are, how they work and how to make sure that they don’t make your programs crash.
This is not a course for beginners. It is aimed at programmers who already have a good working knowledge of C programming and who need to take the next step in mastering C by gaining a deep understanding of pointers.
If you’ve struggled with pointers and can’t quite figure out what all those ‘arrow diagrams’ really mean or what exactly is the relationship between pointers and addresses, this is the course for you. In a series of short, tightly-targeted lessons, you will learn all about:
The source code for all the example programs is provided, so if you need to try out my code you can load it and run it in your preferred C IDE or code editor.
Who this course is for and what you will get out of it.
What is in the course and how should you study it?
Pointers and addresses - how are they related?
How to create and use a pointer variable in C.
Dereferencing to get at the data that is ‘pointed to’.
What are pointers?
This document contains some brief notes on topics covered in Step One of the course. You may want to refer to use these notes as a revision aid or to help clarify important points from this section.
The address of the array is the same as the address of the first item in the array. Why is that important?
How can pointer values be displayed?
Let’s see how pointers and addresses work – and why arrays are special.
Pointers to pointers
Pointers to pointers to integers
Arrays of arrays of characters
What is **argv in the main() function?
Pointers to void
Setting aside storage space
How to allocate the right amount of memory for a specific amount of data
Why does your C compiler will complain about some functions?
How to clear memory before allocating
How to free memory that is no longer needed
How to change the size of a block of allocated memory
What does it mean when you add 1 to a pointer?
Using pointer arithmetic with arrays
But how much memory does a struct need?
Why the order of fields in a struct is important
Understanding that data types of a certain size are aligned on boundaries of that size
Pointer arithmetic works with complex types as well as simple types
Still confused by pointers? Here I show how to use your debugger to understand indirection
Here’s another example of how to use a debugger with multiple indirection – pointers to pointers to pointers, and see how they are stored in memory
The relationship between pointers, addresses and data stored in memory
This document contains some brief notes on topics covered in Step Two of the course. You may want to refer to use these notes as a revision aid or to help clarify important points from this section.
Limitations of arrays and using linked lists as an alternative
How is a linked list different from an array?
Lists that include one pointer linking each element to the next one
Do you really always need to free memory?
Lists whose elements contain pointers to each adjacent element
An example showing how to create a simple double-linked list
Initializing a doubly-linked list not quite as simple as initializing a singly-linked list
A sample project showing a doubly-linked list
Queues are very common data structures in programming – here I explain what they are
Using a doubly linked list as a queue
A stack is another important type of data structure – here we see how it differs from a queue
You may need pointers with a stack, but you may not need a linked list
Adding and removing items to and from a stack
Iterating over list elements
Making a new copy of an existing queue
How would you delete an item from the middle of a list?
How would you add an item into a list?
What is a function pointer and what are they for?
The strange syntax for declaring a function pointer
How a single piece of code can call different functions using function pointers
Pointers in linked lists, queues and stacks
This document contains some brief notes on topics covered in Step Three of the course. You may want to refer to use these notes as a revision aid or to help clarify important points from this section.
Pointers are one of the major sources of error in C programs. But why?
When is a copy not a copy?
Sometimes a copy may not be what you think it is!
Allocating the wrong amount of memory is a recipe for disaster
When you cast a pointer you are not really changing anything. But an incorrect cast can cause problems even so
An example of a cast that didn’t work as expected
What happens if you free some memory twice?
When memory is allocated but not freed
What happens when you try to use memory that has already been freed?
Trying to access things that can’t be accessed
What happens if you use a pointer that doesn’t point to anything?
Some common sources of error in C programs.
This document contains some brief notes on topics covered in Step Four of the course. You may want to refer to use these notes as a revision aid or to help clarify important points from this section.
That’s it! So where to next? Here are a few pointers…
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.