text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
to run a program or you type dot slash
something in the Linux command line | 182.26 | 3.99 |
environment in order to run a program,
the bits that compose your program | 186.25 | 3.83 |
are loaded also into memory
up into this region here. | 190.08 | 4.1 |
So, at the end of the day, you have
access to just pretty generic memory, | 194.18 | 3.92 |
but we use it in these different ways. | 198.1 | 1.74 |
And it allows us to
ultimately solve problems | 199.84 | 2.88 |
that we might not have
been able to in the past. | 202.72 | 2.646 |
Recall for instance this example here,
deliberately shown in red because it | 205.366 | 3.124 |
was [? buggy. ?] This does not work. | 208.49 | 2.09 |
Now, logically, it does do the swap that
we intend whereby a goes into b and b | 210.58 | 6.24 |
goes into a. | 216.82 | 0.74 |
And we achieve that result by
way of this temporary variable | 217.56 | 2.5 |
so that we have a temporary placeholder
into which to store one of those values | 220.06 | 4.14 |
while doing the swap. | 224.2 | 1.31 |
But it had no permanent impact on the
two variables that were passed into it. | 225.51 | 5.02 |
And that was because by default in C any
time you pass arguments to a function, | 230.53 | 3.46 |
those arguments are passed
so to speak, by value. | 233.99 | 2.83 |
You get copies of those values
being passed into a function. | 236.82 | 3.49 |
And so, if main, for instance,
has two variables, x and y-- | 240.31 | 3.29 |
as they did last time--
and you pass x and y | 243.6 | 2.19 |
into a function like this
one here swap, x and y | 245.79 | 3.16 |
are going to get copied
as a and b respectively. | 248.95 | 2.75 |
So you might perfectly,
logically, correctly swap a and b, | 251.7 | 3.63 |
but you're having no permanent
impact on x and y themselves. | 255.33 | 5.129 |
But what if, per this
green version here, | 260.459 | 3.071 |
we reimplement swap to be
a little more complicated | 263.53 | 3.15 |
looking, but at the end of
the day actually correct? | 266.68 | 3.47 |
Notice now we've declared
a and b not to be | 270.15 | 2.38 |
integers but to be pointers to
integers, the addresses of integers. | 272.53 | 4.61 |
And that's what's implied by
the star that we're putting | 277.14 | 2.51 |
right there before the variable's name. | 279.65 | 1.89 |
Meanwhile, inside of the
body of this function, | 281.54 | 2.004 |
we still have three lines of code. | 283.544 | 1.416 |
And we're still using a temporary
variable, and that in itself | 284.96 | 2.86 |
is not a pointer. | 287.82 | 0.73 |
It's just an integer
as before, but notice | 288.55 | 2.44 |
we're using this star notation
again, albeit for a different purpose | 290.99 | 3.18 |
to actually dereference these pointers. | 294.17 | 2.58 |
Recall that int star a and int star
b means give me a variable that | 296.75 | 5.4 |
can store the address of an integer. | 302.15 | 1.86 |
That's declaring a pointer. | 304.01 | 1.81 |
Meanwhile, if you just say star
a without declaring something | 305.82 | 3.8 |
to the left of it with
a data type like int, | 309.62 | 1.99 |
you're saying go to the
address that is in a. | 311.61 | 3.02 |
So if a is an address,
star a is at that address, | 314.63 | 4.02 |
which of course per its declaration
is going to be an integer. | 318.65 | 3.11 |
Similarly, star b means
go to the address in b. | 321.76 | 2.4 |
Star a means go to the address in a
and put the former into the latter, | 324.16 | 5.35 |
ultimately putting the value of temp at
the address in b-- so absolutely more | 329.51 | 4.36 |
complicated at first glance,
but if you consider again | 333.87 | 2.25 |
the first principles of what's
going on here, all we are doing | 336.12 | 3.31 |
are moving things around in memory. | 339.43 | 3.027 |
And we can do that now
because we have the ability | 342.457 | 2.083 |
to express the locations, the
numeric locations of where | 344.54 | 2.91 |
things are in memory. | 347.45 | 1.05 |
But nicely enough, we,
the programmer, don't have | 348.5 | 2.28 |
to care where things are in memory. | 350.78 | 1.97 |
We can access things symbolically
as we're doing here with a and b. | 352.75 | 4.33 |
So even though we might
have seen on the screen | 357.08 | 2.18 |
or you might see while debugging
actual addresses of memory, | 359.26 | 3.37 |
rarely does that actually
matter in practice. | 362.63 | 3.02 |
We can deal with everything we've
learned thus far symbolically. | 365.65 | 3.58 |
Now, last time we also took a
look at the world of forensics, | 369.23 | 3.57 |
and we took a look at how images are
implemented and specifically file | 372.8 | 3.1 |
formats like BNP, and JPEG,
and GIF, and yet others. | 375.9 | 3.61 |
And we glanced into [? Asmila's ?]
here as we tried to enhance this image, | 379.51 | 4.13 |
but of course, there was only
finite amount of information. | 383.64 | 3.64 |
So, what you see is what you get
in terms of any kind of glint | 387.28 | 3.07 |
or suspect in her eyes. | 390.35 | 1.91 |
But we did this in part
so that we could also | 392.26 | 2.1 |
introduce another feature of C that
allows us to declare our own data | 394.36 | 4.06 |
types, indeed our own data structures. | 398.42 | 2.697 |
For instance, we proposed
that if you wanted | 401.117 | 1.833 |
to write a program
that stores a student, | 402.95 | 3.1 |
you could actually declare
your own student data type | 406.05 | 2.93 |
inside of which is a name and
inside of which is a dorm, | 408.98 | 3.87 |
and anything else that
you might actually want. | 412.85 | 2.15 |
Meanwhile, this syntax here gives
us a new data type called student | 415 | 4.35 |
so that if we want to write a
program that implements students, | 419.35 | 2.73 |
we can actually wrap related
information together like name and dorm | 422.08 | 4.18 |
without having to maintain
a whole bunch of strings | 426.26 | 2.872 |
for just names and a whole
bunch of strings for just dorms. | 429.132 | 2.458 |
We can actually encapsulate things
all inside of one structure. | 431.59 | 3.69 |
And indeed encapsulation is another
principle of computer science | 435.28 | 3.09 |
that you'll see throughout program
and throughout the field itself. | 438.37 | 3.98 |
So, what do we now do this time? | 442.35 | 2.38 |
So, today we introduce more
sophisticated ingredients | 444.73 | 4.07 |
with which we can solve problems and
we revisit a problem from the past | 448.8 | 3.7 |
that we thought we had rather
knocked off and had solved. | 452.5 | 2.86 |
So, this might represent
a whole bunch of names, | 455.36 | 2.91 |
a whole bunch of numbers, a whole bunch
of telephone numbers in a phone book | 458.27 | 3.87 |
back to back to back to
back stored in this case | 462.14 | 2.67 |
in the form of an array, the simplest
of data structure, so to speak, | 464.81 | 3.11 |
that we've discussed thus far. | 467.92 | 1.25 |
And an array, again, is a contiguous
block of memory each of whose element-- | 469.17 | 4.5 |
typically are of the same data type,
integers, or strings, or the like-- | 473.67 | 3.82 |
and they are by definition
back to back to back to back, | 477.49 | 3.03 |
which allows you random access. | 480.52 | 1.56 |
Which means you can jump
to any of these locations | 482.08 | 2.083 |
instantly just by using in C
that square bracket notation | 484.163 | 2.957 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.