text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
is this, get the value in temp-- that's
easy-- and put it at the address in b. | 3,220.8 | 5.53 |
So we have to go to b
and put temp in there. | 3,226.33 | 3.29 |
So to do that, here's
temp, it's the number 1. | 3,229.62 | 4.35 |
I have to go to the address in b. | 3,233.97 | 1.69 |
The address and b is 92. | 3,235.66 | 1.18 |
So let's go there, and
aha, let me go ahead then, | 3,236.84 | 3.44 |
and overwrite the value that's
there with the number 1. | 3,240.28 | 7.39 |
So now this frame of
memory on the stack-- | 3,247.67 | 3.5 |
the 91, the 92, and the
temporary variable-- | 3,251.17 | 2.45 |
they are, by design of my
new function, disposable. | 3,253.62 | 3.43 |
I really don't care, after swap
returns, if those things continue-- | 3,257.05 | 5.07 |
I did care a little bit about that. | 3,262.12 | 1.46 |
I don't care if those
things continue to exist. | 3,267.43 | 2.52 |
All I care about is that
x and y continue to exist. | 3,269.95 | 4.21 |
So in this way is the new and
improved version of the swap function | 3,274.16 | 3.91 |
actually having a permanent
impact on my data? | 3,278.07 | 2.89 |
And with the frame, the
memory still looks like that, | 3,280.96 | 3.07 |
because it's gone to the address in a. | 3,284.03 | 2.01 |
Gone to the address in b, which
leads it to the original x and y. | 3,286.04 | 4.15 |
And so by way of pointers,
by way of these addresses, | 3,290.19 | 2.87 |
do we have the ability to actually
go much, much deeper into a program | 3,293.06 | 4.75 |
and actually get at
values that previously we | 3,297.81 | 3.43 |
had no way of even expressing. | 3,301.24 | 3.04 |
So it's at this point in the story where
I usually admit that, at least for me, | 3,304.28 | 5.13 |
this has been among the most challenging
topics when I, myself, was a student. | 3,309.41 | 3.91 |
And in fact, all these years later--
it's like, 20, 20 year-- yeah, | 3,313.32 | 2.905 |
I think we're up to 20 years ago. | 3,316.225 | 1.375 |
20 years ago-- I didn't
take this photo then-- | 3,317.6 | 2.96 |
but I sat in what was, at the time,
the back right hand corner of Elliot | 3,320.56 | 3.59 |
House's dining hall, here at Harvard. | 3,324.15 | 2.07 |
And I sat down with my teaching
fellow, who of all the TFs I had | 3,326.22 | 2.93 |
as an undergrad, still remember to
this day, [? Nishat ?] [? Meda ?]. | 3,329.15 | 2.42 |
And we just reconnected on
Facebook, all these years later. | 3,331.57 | 2.52 |
Very exciting. | 3,334.09 | 0.96 |
And it was he who
wonderfully sat down with me | 3,335.05 | 2.419 |
at office hours one
day in the dining hall, | 3,337.469 | 1.791 |
trying to help me understand pointers,
because it was just so much more | 3,339.26 | 3.03 |
technical than all the other stuff. | 3,342.29 | 1.458 |
Like, there is no puzzle piece in
Scratch for the address of something | 3,343.748 | 3.142 |
that leads you somewhere so
powerfully as these stars seem | 3,346.89 | 3.53 |
to be able to, here. | 3,350.42 | 1.011 |
And this is only to say that
this is among those topics that | 3,351.431 | 2.499 |
might take a little bit of
time to sink in, but it does. | 3,353.93 | 3.33 |
And when it does, it really is that
proverbial light bulb that goes off. | 3,357.26 | 3.39 |
And for me, that light bulb
went off right then and there. | 3,360.65 | 4.9 |
Now, what more can we do with these
things, after that motivational speech? | 3,365.55 | 3.37 |
Pointer arithmetic. | 3,368.92 | 1.22 |
So, sort of complicated sounding
topic, but really, it just | 3,370.14 | 3.58 |
goes back to first principles,
as to what a pointer actually is. | 3,373.72 | 3.12 |
And it allows us now
to do things like this. | 3,376.84 | 1.99 |
Let me go ahead and open up one other
program that I wrote in advance here, | 3,378.83 | 3.38 |
called pointers dot c. | 3,382.21 | 2.11 |
And take a look at what
this thing does here. | 3,384.32 | 2.42 |
It works a little differently
from the syntax we're used to, | 3,386.74 | 2.72 |
and from any of our
crypto problems thus far. | 3,389.46 | 3.09 |
So notice on this first line here,
I get string and I store in s. | 3,392.55 | 4.08 |
No more string right
now, just char star. | 3,396.63 | 1.85 |
We can be real and talk about
it as the address of a char. | 3,398.48 | 3.55 |
A little sanity check,
is s equal equal to null? | 3,402.03 | 2.44 |
If so, just return. | 3,404.47 | 0.94 |
Something went wrong, so
let's not deal with it now. | 3,405.41 | 2.32 |
Down here, a for loop. | 3,407.73 | 1.75 |
For i gets 0 all the way up to n. | 3,409.48 | 3.71 |
So this is just a standard syntax
we've used a few times now, even back | 3,413.19 | 3.05 |
in week 1 when we just
wanted iterate over. | 3,416.24 | 2.36 |
Or in week 2, when we wanted iterate
over the characters in a string. | 3,418.6 | 3.67 |
But we've never seen this
kind of craziness before. | 3,422.27 | 2.85 |
A star, and then some
arithmetic in parentheses. | 3,425.12 | 3.47 |
In the past, when we wanted to print
out a character, as implied by %c here, | 3,428.59 | 5 |
we quite simply, as I recall, did this. | 3,433.59 | 3.7 |
Which was nice and intuitive, right? | 3,437.29 | 1.5 |
The square brackets
denote to treat the string | 3,438.79 | 2.327 |
as though it's an array, which it
really is, an array of characters. | 3,441.117 | 2.833 |
And that means get the
i-th character of s. | 3,443.95 | 3.05 |
But now that we understand what s is, we
don't need to use this syntactic sugar, | 3,447 | 5.12 |
as it's called. | 3,452.12 | 0.64 |
Any time a language has a
feature that's convenient to use, | 3,452.76 | 2.92 |
and easier to read sometimes,
but isn't fundamentally | 3,455.68 | 2.69 |
necessary to express
yourself, it's often | 3,458.37 | 1.75 |
called syntactic sugar, which means
it's just kind of a nicety to have. | 3,460.12 | 3.89 |
And indeed, that square
bracket notation is just | 3,464.01 | 2.98 |
sugar for this more arcane, but
perhaps more well-defined syntax now. | 3,466.99 | 7.42 |
The star operator in this context is
the dereference operator, technically. | 3,474.41 | 4.5 |
It's the go there operator,
as I've been describing it. | 3,478.91 | 2.94 |
Go to some address. | 3,481.85 | 1.52 |
Well s, recall, is a string. | 3,483.37 | 1.91 |
But there is no string. | 3,485.28 | 1.27 |
Strings are just the
addresses of characters now. | 3,486.55 | 2.32 |
The first in a string. | 3,488.87 | 1.94 |
So initially in this
loop, what am I doing? | 3,490.81 | 3.42 |
s is the address of a string, the
address of its first character. | 3,494.23 | 3.33 |
And I'm saying, add to s, the value i. | 3,497.56 | 2.7 |
Well, i is just this variable in my
for loop that's initialized to 0. | 3,500.26 | 4.27 |
So s plus 0 is obviously just s. | 3,504.53 | 3.19 |
s is the address of a char. | 3,507.72 | 1.86 |
*s means go to s. | 3,509.58 | 2.97 |
What do you find when you get there? | 3,512.55 | 1.91 |
A character, because s is a char
star, the address of a character. | 3,514.46 | 3.82 |
And so printing out %c
*s effectively means, | 3,518.28 | 4.41 |
go print that character right there. | 3,522.69 | 2.2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.