Save this video free

Lecture 23: Arrays (continued)

Burton Ma · 45:44 · Watch on YouTube

Part of Queen's University CISC220. See all 23 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Burton Ma explains how C pointer arithmetic can traverse arrays and how array parameters decay to pointers, leaving functions without the array length unless callers pass it explicitly. He also compares ways to return array data, showing why returning a local array is invalid, how dynamic allocation provides longer-lived storage, and why a pointer-to-pointer or static array changes the API's behavior.

Key takeaways

Chapters

0:00 Pointer Comparisons and Pre- versus Post-Increment
6:00 Forward Pointer Traversal and Unsigned Countdown Bugs
15:00 Traversing an Array Backward with a Pointer
17:15 Array Parameters Decay to Pointers in C
21:00 Passing Array Lengths and Using Sentinel Values
25:00 Why Returning a Local Array Pointer Fails
29:00 Allocating Returnable Array Storage with malloc
36:00 Returning an Array Pointer Through a Pointer-to-Pointer
43:00 Static Arrays Avoid Expiration but Reuse One Buffer

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:01 Okay, good afternoon everybody. So in the last lecture we were talking about arrays um and in particular we were talking about how arrays and pointers are related to one another. Uh so today I want to start by Well, I guess we're going to finish off this lecture and then um perhaps move on to the next lecture if there's time. Um so in the previous uh where where did we end? So we ended um by after talking about comparing pointers. So if you have two pointers P and Q and they're both pointers to the same array into the same array, uh you can use the comparison operators to determine whether or not uh P points at an element that is before or after um the pointer Q. Right? So if P is less than Q, then you

0:49 know that P is pointing at an element uh whose index is less than the index of Q. If P is greater than Q is true, then you know that P is pointing at an element uh whose index is greater than that of the element Q. So the pointer Uh sorry, the comparison operators let you compare the locations of two pointers. Uh and there's a little example here um that we looked at before we ended the class. Uh so it's a little bit uncommon to compare the the the locations of pointers. Um what's more common um is to use pointer arithmetic uh and to manipulate the position of a pointer using the operators plus equals,

1:36 minus equals, plus plus, and minus minus. So if you're not familiar with the plus equals operator, plus equals means uh so P plus equals N means uh add N to the value of P. Right? So this is true whether or not P

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Burton Ma.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.