text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
So now let's re-compile this program, do dot slash floats.
3,241.14
3.56
>> And for the third time, let's see if it meets my expectations.
3,244.7
3.25
1, 10, enter, yes, OK, 1.000, divided by 10.000, is 0.100000.
3,247.95
13.53
And it turns out we can control how many numbers are after those decimal points.
3,261.48
3.472
We actually will.
3,264.952
0.708
We'll come back to that.
3,265.66
1.13
>> But now, in fact, the math is correct.
3,266.79
1.65
So, again, what's the takeaway here?
3,268.44
1.65
It turns out that in C, there are not only just strings-- and, in fact,
3,270.09
2.96
there aren't really, because we add those with the CS50 library.
3,273.05
3.07
But there aren't just ints.
3,276.12
1.59
>> There are also floats.
3,277.71
1.28
And it turns out a bunch of other data types too, that we'll use before long.
3,278.99
3.82
Turns out if you want a single character, not a string of characters,
3,282.81
3.46
you can use just a char.
3,286.27
1.34
>> Turns out that if you want a bool, a Boolean value, true or false only,
3,287.61
4.74
thanks to the CS50 library, we've added to C the bool data type as well.
3,292.35
4.49
But it's also present in many other languages as well.
3,296.84
2.34
And it turns out that sometimes you need bigger numbers then come by default
3,299.18
4.95
with ints and floats.
3,304.13
1.08
>> And, in fact, a double is a number that uses not 32 bits, but 64 bits.
3,305.21
5.38
And a long long is a number that uses not 32, bits but 64 bits,
3,310.59
4.4
respectively, for floating point values and integers, respectively.
3,314.99
4.2
So let's actually now see this in action.
3,319.19
3.59
>> I'm going to go ahead here and whip up one other program.
3,322.78
3.37
Here, I'm going to go ahead and do include CS50.h.
3,326.15
5.87
And let me go, include standard IO.h.
3,332.02
2.89
>> And you'll notice something funky is happening here.
3,334.91
2.41
It's not color coding things in the same way as it did before.
3,337.32
3.272
And it turns out, that's because I haven't given the thing a file name.
3,340.592
2.958
>> I'm going to call this one sizeof.c, and hit Save.
3,343.55
3.72
And notice what happens to my very white code against that black backdrop.
3,347.27
3.769
Now, at least there's some purple in there.
3,351.039
1.791
And it is syntax highlighted.
3,352.83
1.66
>> That's because, quite simply, I've told the IDE what type of file
3,354.49
3.21
it is by giving it a name, and specifically a file extension.
3,357.7
3.36
Now, let's go ahead and do this.
3,361.06
2.56
I'm going to go ahead and very simply print out the following-- bool
3,363.62
5.29
is percent LU.
3,368.91
2.17
>> We'll come back to that in just a moment.
3,371.08
1.87
And then I'm going to print size of bool.
3,372.95
2.89
And now, just to save myself some time, I'm
3,375.84
2.33
going to do a whole bunch of these at once.
3,378.17
2.11
And, specifically, I'm going to change this to a char and char.
3,380.28
4.34
This one, I'm going to change to a double and a double.
3,384.62
3.14
>> This one, I'm going to change to a float and a float.
3,387.76
3.68
This one, I'm going to change to an int and an int.
3,391.44
4.23
And this one, I'm going to change to a long long.
3,395.67
2.99
And it's still taking a long time, long long.
3,398.66
2.18
>> And then, lastly, I gave myself one too many, string.
3,400.84
3.732
It turns out that in C, there's the special operator called
3,404.572
2.458
size of that's literally going to, when run,
3,407.03
3.23
tell us the size of each of these variables.
3,410.26
1.839
And this is a way, now, we can connect back
3,412.099
1.791
to last week's discussion of data and representation.
3,413.89
3.25
>> Let me go ahead and compile size of dot slash size of.
3,417.14
3.19
And let's see.
3,420.33
0.88
It turns out that in C, specifically on CS50 IDE,
3,421.21
4
specifically on the operating system Ubuntu,
3,425.21
2.96
which is a 64-bit operating system in this case,
3,428.17
2.93
a bool is going to use one byte of space.
3,431.1
3.089
That's how size is measured, not in bits, but in bytes.
3,434.189
2.291
And recall that one byte is eight bits.
3,436.48
2.21
So a bool, even though you technically only need a 0 or 1,
3,438.69
3.34
it's a little wasteful how we've implemented it.
3,442.03
2.062
It's actually going to use a whole byte-- so all zeros, are maybe
3,444.092
2.708
all ones, or something like that, or just one 1 among eight bits.
3,446.8
4.25
>> A char, meanwhile, used for a character like an Ascii character per last week,
3,451.05
3.912
is going to be one character.
3,454.962
1.208
And that synchs up with our notion of it being no more than 256 bits-- rather,
3,456.17
6.17
synchs up with it being no longer than 8 bits, which
3,462.34
3.02
gives us as many as 256 values.
3,465.36
2.09
A double is going to be 8 bytes or 64 bits.
3,467.45
2.23
>> A float is 4.
3,469.68
0.83
An int is 4.
3,470.51
1.18
A long, long is 8.
3,471.69
1.29
And a string is 8.
3,472.98
1.736
But don't worry about that.
3,474.716
1.124
We're going to peel back that layer.
3,475.84
1.5
It turns out, strings can be longer than 8 bytes.
3,477.34
2.6
>> And, indeed, we've written strings already, hello world,
3,479.94
2.37
longer than 8 bytes.
3,482.31
1.39
But we'll come back to that in just a moment.
3,483.7
2.57
But the take away here is the following.
3,486.27
3.42
>> Any computer only has a finite amount of memory and space.
3,489.69
5.63
You can only store so many files on your Mac or PC.
3,495.32
2.54
You can only store so many programs in RAM running at once, necessarily, even
3,497.86
5.17
with virtual memory, because you have a finite amount of RAM.
3,503.03
3.33
>> And just to picture-- if you've never opened up a laptop
3,506.36
2.63
or ordered extra memory for a computer, you
3,508.99
2.31
might not know that inside of your computer
3,511.3
2.37
is something that looks a little like this.
3,513.67
2.92
So this is just a common company named Crucial that makes RAM for computers.
3,516.59
3.95
And RAM is where programs live while they're running.
3,520.54
3.08
>> So on every Mac or PC, when you double click a program, and it opens up,
3,523.62
3.01
and it opens some Word document or something like that,
3,526.63
2.291
it stores it temporarily in RAM, because RAM is faster
3,528.921
2.843
than your hard disk, or your solid state disk.
3,531.764
1.916
So it's just where programs go to live when they're running,
3,533.68
2.92
or when files are being used.
3,536.6
1.46