text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
So for instance, if the address of a is say,
2,892.08
3.78
33 Oxford Street, Cambridge, Massachusetts.
2,895.86
2.739
That happens to be the address of the CS building at Harvard.
2,898.599
2.541
Star a means go to 33 Oxford Street in Cambridge, Massachusetts.
2,901.14
5.06
The star just means go to that particular address.
2,906.2
4.12
So what does that mean, then, down here, when I say star a gets star b?
2,910.32
4.17
That means go to the address in b and get its value,
2,914.49
3.56
and store it at whenever a is pointing at to.
2,918.05
3.45
So go to a and wait for me for a value.
2,921.5
2.97
Go to b, get a value, and put that value at the location in a.
2,924.47
4.61
And then lastly, this just means go to the location in b,
2,929.08
3.645
go to whatever building that is, so to speak,
2,932.725
2.295
and put the value that is in temp inside of that building.
2,935.02
4.88
So a pointer is just an address.
2,939.9
2.96
These stars just mean pointers are involved.
2,942.86
3.75
Give me the address of an int, give me the address of an int.
2,946.61
3.04
And again, confusing, admittedly, the star
2,949.65
2.58
in this context where we don't have the word int in front of it again,
2,952.23
3.73
on the side of the equal sign, just means go to that address.
2,955.96
2.83
Go to that building.
2,958.79
1.29
Go to that other building and put something there.
2,960.08
3.55
So we can now fix our swap program correctly.
2,963.63
3.98
We can now open up, as I will here, swap dot c, which I wrote in advance.
2,967.61
5.1
That looks almost the same, except that I've changed the swap function
2,972.71
3.94
as follows. a is now int*, b is now int*,
2,976.65
3.5
and I also borrowed the stars inside of the function, as well.
2,980.15
3.62
But something's gotta change.
2,983.77
1.88
There's one more line of code I need to change for all of this to work.
2,985.65
4.46
What is that?
2,990.11
0.67
What line needs to change?
2,994.161
1.649
Well who cares about swap?
2,995.81
1.73
It's main that was calling this thing in the first place,
2,997.54
3.07
so let's go back to the original story.
3,000.61
2.29
Main, here, declares x and y as 1 and 2, does some printfs here, as before.
3,002.9
5.73
But notice this line has to change.
3,008.63
1.64
So one more piece of syntax today.
3,010.27
2.739
And we're running out of new symbols.
3,013.009
1.541
We've seen most of C already.
3,014.55
2.11
&x and &y means get me the address of x, and get me the address of y,
3,016.66
7
and pass those in instead.
3,023.66
1.89
So x,y would just mean pass in a copy of x and a copy of y,
3,025.55
4.11
or the values thereof.
3,029.66
2.23
&x &y means give me a little, you know, map with the address of x and a little
3,031.89
5.36
map with the address of y, so that swap-- who's receiving those maps--
3,037.25
4.71
can go there.
3,041.96
1.98
So what does this mean in pictorial form?
3,043.94
2.81
If we now go back to the beginning of this story,
3,046.75
2.26
where we were looking at my computer's memory as this big rectangular region
3,049.01
4.53
like this.
3,053.54
1.26
With main's chunk of memory at the bottom here.
3,054.8
4.61
And inside of main was two variables, like x, and another variable y.
3,059.41
6.16
And inside of those were the numbers 1 and 2.
3,065.57
3.4
And then I called swap.
3,068.97
1.92
And so swap gets its own frame on the stack, so to speak.
3,070.89
3.57
This is swap's frame.
3,074.46
1.77
It, too, had a variable called a and a variable called b.
3,076.23
6.472
But what goes in there now?
3,082.702
1.638
It's not 1 and 2.
3,084.34
1.49
We need to know a little something more about my computer's memory.
3,085.83
2.8
And I don't know where everything's laid out,
3,088.63
2.22
but let me just arbitrarily assume that, you know,
3,090.85
3.42
it's inside of my computer's memory.
3,094.27
1.92
Maybe this is byte number 90.
3,096.19
2.48
This is going to be 91.
3,098.67
1.97
This here is going to be 92, 93, 94, 95, and so forth.
3,100.64
3.91
I just need to know that there's some kind of numbering scheme there.
3,104.55
3.33
So what goes inside of a is 91.
3,107.88
3.51
What goes inside of b is 92.
3,111.39
3.94
And not the values 1 and 2, but rather the addresses of those values 1 and 2.
3,115.33
7.22
Because now my code for the swap function, consider what it does.
3,122.55
4.23
It says, upon receiving the address of an integer,
3,126.78
3.44
called a, upon receiving the address of another integer, called b,
3,130.22
4.531
go there and store that value in temp.
3,134.751
3.469
Go to the address in b and store that value at the address in a.
3,138.22
4.46
Store the value in temp at the address in b.
3,142.68
3.6
So let's see what happens then.
3,146.28
2.26
So first of all, I need another variable here, called temp.
3,148.54
4.51
Temp, meanwhile, is not a pointer.
3,153.05
3.56
It's just an integer, but what does it store?
3,156.61
3.54
Well, according to my code, temp gets the value
3,160.15
4.55
of going to a, going to the address in a.
3,164.7
3.25
So what is a?
3,167.95
1.583
a is 99.
3,169.533
1.777
That's like a treasure map leading to, OK, this chunk of memory
3,171.31
3.4
down here in my computer.
3,174.71
1.61
And what value is there once I've gone there?
3,176.32
2.11
Once I've gone to the CS building inside of it, I see the number 1,
3,178.43
3.8
and so I put the number 1 in temp.
3,182.23
3.12
Meanwhile, my second line of code says go to the address in b
3,185.35
4.795
and grab its value, and put it at the address that's in a.
3,190.145
5.015
So what does that mean?
3,195.16
1.64
Well, star b means start here and go to 92.
3,196.8
4.767
So it's like an arrow-- kind of like chutes and ladders,
3,201.567
2.333
if you know the game-- like go to address 92.
3,203.9
2.64
What value is there?
3,206.54
0.99
The number 2.
3,207.53
0.98
And the other half of the equation, on the left,
3,208.51
2
said, go to the address in a, which is here,
3,210.51
2.79
and copy the 2 into that location.
3,213.3
4.89
And then the last line-- only one more line--
3,218.19
2.61