In Lesson 6 of Learn C With Me, we continue our exploration of arrays in C, picking up exactly where the previous stream left off.
This time, arrays meet pointers. We take a closer look at the relationship between the two and start exploring what actually happens when arrays are passed to functions.
We cover:
- A quick recap of arrays from the previous lesson
- The relationship between arrays and pointers
- Getting a pointer to an array element
- The address of the first element of an array
- Using an array name as a pointer to its first element
- Pointer arithmetic with arrays
- Understanding expressions such as
a + 1 - The relationship between
a[n]and pointer arithmetic - Passing one-dimensional arrays to functions
- Different ways of declaring array parameters
- Changing array contents inside functions
- Why arrays behave differently from ordinary pass-by-value variables
- Passing multidimensional arrays to functions
- How array dimensions are specified in function parameters
A particularly useful part of this lesson is seeing how closely C arrays and pointers are connected. What initially looks like some rather strange syntax starts making more sense once we look at the addresses and understand what the compiler is actually doing.
As usual, we don’t just accept everything at face value. We stop, experiment with the code, make predictions, get some of them wrong, compile the examples, and use the results — along with help from the live chat — to build a better mental model of how C works.
This is Part Two of our arrays lesson, continuing directly from the previous stream. The topic turns out to be bigger than expected, so we’re not done with arrays just yet.