{"captions":[{"content":"[Section 4] [Less Comfortable]","startTime":0,"duration":2000,"startOfParagraph":false},{"content":"[Nate Hardison] [Harvard University]","startTime":2000,"duration":2000,"startOfParagraph":false},{"content":"[This is CS50.] [CS50.TV]","startTime":4000,"duration":3000,"startOfParagraph":false},{"content":"All right, welcome back to section.","startTime":7000,"duration":3000,"startOfParagraph":true},{"content":"In this week's section we're going to do a couple of things.","startTime":10000,"duration":3000,"startOfParagraph":false},{"content":"We're going to first recap Problem Set 2,","startTime":13000,"duration":4000,"startOfParagraph":false},{"content":"which is the Caesar and Vigenère problem set.","startTime":17000,"duration":3000,"startOfParagraph":false},{"content":"And then we're going to dive into Quiz 0 review","startTime":20000,"duration":3000,"startOfParagraph":false},{"content":"and spend a little bit of time recapping what we've talked about ","startTime":23000,"duration":3000,"startOfParagraph":false},{"content":"in each of the lectures so far, and we'll also do a few problems","startTime":26000,"duration":4000,"startOfParagraph":false},{"content":"from previous year's quizzes.","startTime":30000,"duration":2000,"startOfParagraph":false},{"content":"That way you guys have a good way to prepare for that.","startTime":32000,"duration":4000,"startOfParagraph":false},{"content":"To start, I've booted up a couple of good solutions","startTime":36000,"duration":4000,"startOfParagraph":true},{"content":"for the previous problem set, Problem Set 2, into this space.","startTime":40000,"duration":5000,"startOfParagraph":false},{"content":"If you guys all hit this link, ","startTime":45000,"duration":3000,"startOfParagraph":false},{"content":"and if you click my name and click on my first revision","startTime":48000,"duration":5000,"startOfParagraph":false},{"content":"you'll see caesar.c, which is exactly what I'm looking at.","startTime":53000,"duration":3000,"startOfParagraph":false},{"content":"Let's talk about this really quickly.","startTime":56000,"duration":4000,"startOfParagraph":false},{"content":"This is just a sample solution.","startTime":60000,"duration":2000,"startOfParagraph":false},{"content":"This is not necessarily the perfect solution.","startTime":62000,"duration":3000,"startOfParagraph":false},{"content":"There are many different ways to write this,","startTime":65000,"duration":3000,"startOfParagraph":false},{"content":"but there are a few things that I wanted to highlight","startTime":68000,"duration":2000,"startOfParagraph":false},{"content":"that I saw as I was grading, common mistakes that I think","startTime":70000,"duration":3000,"startOfParagraph":false},{"content":"this solution does a very good job of handling.","startTime":73000,"duration":5000,"startOfParagraph":false},{"content":"The first is having some sort of header comment at the top.","startTime":78000,"duration":4000,"startOfParagraph":true},{"content":"On lines 1 through 7 you see the details,","startTime":82000,"duration":3000,"startOfParagraph":false},{"content":"what exactly this program is doing.","startTime":85000,"duration":3000,"startOfParagraph":false},{"content":"A good standard practice when you're writing C code","startTime":88000,"duration":4000,"startOfParagraph":false},{"content":"regardless if your program is contained within a single file or ","startTime":92000,"duration":3000,"startOfParagraph":false},{"content":"whether it's split over multiple files is to have some sort of ","startTime":95000,"duration":3000,"startOfParagraph":false},{"content":"orienting comment at the top.","startTime":98000,"duration":2000,"startOfParagraph":false},{"content":"This is also for people who go out and write code in the real world.","startTime":100000,"duration":3000,"startOfParagraph":false},{"content":"This is where they'll put copyright information.","startTime":103000,"duration":4000,"startOfParagraph":false},{"content":"Below are the #includes.","startTime":107000,"duration":3000,"startOfParagraph":false},{"content":"On line 16 there's this #define, which we'll come back to in just a bit.","startTime":110000,"duration":5000,"startOfParagraph":false},{"content":"And then once the function starts, once main starts,","startTime":115000,"duration":4000,"startOfParagraph":false},{"content":"because this program has been all contained in a single function","startTime":119000,"duration":4000,"startOfParagraph":false},{"content":"the very first thing that happens—and this is very idiomatic and typical of a C program","startTime":123000,"duration":6000,"startOfParagraph":false},{"content":"that takes in command line arguments—is that it immediately checks","startTime":129000,"duration":5000,"startOfParagraph":false},{"content":"for the argument count, argc.","startTime":134000,"duration":4000,"startOfParagraph":true},{"content":"Right here we see that this program is expecting 2 arguments exactly.","startTime":138000,"duration":6000,"startOfParagraph":false},{"content":"Remember there's that first argument that's the special one ","startTime":144000,"duration":3000,"startOfParagraph":false},{"content":"that's always the name of the program that's being run, ","startTime":147000,"duration":2000,"startOfParagraph":false},{"content":"the name of the executable file.","startTime":149000,"duration":2000,"startOfParagraph":false},{"content":"And so what this does is it prevents the user from running the program","startTime":151000,"duration":5000,"startOfParagraph":false},{"content":"with more or fewer arguments.","startTime":156000,"duration":6000,"startOfParagraph":false},{"content":"The reason we want to check for this right away is because ","startTime":162000,"duration":2000,"startOfParagraph":false},{"content":"we can't actually access this argv array right here reliably","startTime":164000,"duration":8000,"startOfParagraph":false},{"content":"until we've checked to see how big it is.","startTime":172000,"duration":3000,"startOfParagraph":false},{"content":"One of the common errors I saw was people would immediately go in","startTime":175000,"duration":3000,"startOfParagraph":true},{"content":"and grab argv[1].","startTime":178000,"duration":3000,"startOfParagraph":false},{"content":"They'd grab the key argument out of the array and do the a to i check on it,","startTime":181000,"duration":5000,"startOfParagraph":false},{"content":"and then they'd do the test for argc as well as the next test,","startTime":186000,"duration":5000,"startOfParagraph":false},{"content":"whether or not the first argument was indeed an integer at the same time,","startTime":191000,"duration":5000,"startOfParagraph":false},{"content":"and that doesn't work because in the case that there are no arguments supplied","startTime":196000,"duration":4000,"startOfParagraph":false},{"content":"you'll be grabbing an argument that isn't there or attempting to grab one that isn't there.","startTime":200000,"duration":6000,"startOfParagraph":false},{"content":"The other big thing that you should notice is that ","startTime":206000,"duration":3000,"startOfParagraph":true},{"content":"you always want to print out some sort of helpful error message","startTime":209000,"duration":3000,"startOfParagraph":false},{"content":"to the user to orient them.","startTime":212000,"duration":2000,"startOfParagraph":false},{"content":"I'm sure you've all run programs where all of a sudden it crashes,","startTime":214000,"duration":3000,"startOfParagraph":false},{"content":"and you get this ridiculous little dialog that pops up and says","startTime":217000,"duration":4000,"startOfParagraph":false},{"content":"something horribly cryptic and maybe gives you an error code or something like that","startTime":221000,"duration":3000,"startOfParagraph":false},{"content":"that makes no sense.","startTime":224000,"duration":3000,"startOfParagraph":false},{"content":"This is where you really want to provide something helpful","startTime":227000,"duration":3000,"startOfParagraph":false},{"content":"and targeted to the user so that when they run it they go \"Oh,\" face palm.","startTime":230000,"duration":4000,"startOfParagraph":false},{"content":"\"I know exactly what to do. I know how to fix this.\"","startTime":234000,"duration":4000,"startOfParagraph":false},{"content":"If you don't print a message, then you end up actually ","startTime":238000,"duration":3000,"startOfParagraph":true},{"content":"leaving the user to go examine your source code","startTime":241000,"duration":3000,"startOfParagraph":false},{"content":"to figure out what went wrong.","startTime":244000,"duration":3000,"startOfParagraph":false},{"content":"There are also some times that you'll use different error codes.","startTime":247000,"duration":4000,"startOfParagraph":false},{"content":"Here we just used one to say there was an error, ","startTime":251000,"duration":3000,"startOfParagraph":false},{"content":"there was an error, there was an error.","startTime":254000,"duration":2000,"startOfParagraph":false},{"content":"Bigger programs, often programs that are called by other programs,","startTime":256000,"duration":4000,"startOfParagraph":false},{"content":"will return some sort of special error codes in different scenarios","startTime":260000,"duration":5000,"startOfParagraph":false},{"content":"to programmatically communicate what you would otherwise ","startTime":265000,"duration":3000,"startOfParagraph":false},{"content":"just use a nice English message for.","startTime":268000,"duration":4000,"startOfParagraph":false},{"content":"Cool.","startTime":272000,"duration":3000,"startOfParagraph":false},{"content":"As we work down, you can see we pull the key out.","startTime":275000,"duration":2000,"startOfParagraph":false},{"content":"We test to see if the key fits.","startTime":277000,"duration":3000,"startOfParagraph":false},{"content":"We get a message from the user.","startTime":280000,"duration":2000,"startOfParagraph":false},{"content":"The reason we do it in this do while loop—and this is something that we will cover","startTime":282000,"duration":4000,"startOfParagraph":false},{"content":"in a little bit—but it turns out that if you type control D","startTime":286000,"duration":4000,"startOfParagraph":false},{"content":"when you get that GetString prompt on the terminal","startTime":290000,"duration":4000,"startOfParagraph":false},{"content":"what that actually does is it sends a special character","startTime":294000,"duration":5000,"startOfParagraph":false},{"content":"to the program.","startTime":299000,"duration":2000,"startOfParagraph":false},{"content":"It's called the ELF or the end of file character.","startTime":301000,"duration":4000,"startOfParagraph":false},{"content":"And in that case, our message string will be null,","startTime":305000,"duration":3000,"startOfParagraph":false},{"content":"so this wasn't something we checked for in the problem set itself.","startTime":308000,"duration":6000,"startOfParagraph":false},{"content":"But as we go on, now that we've started to talk about pointers","startTime":314000,"duration":3000,"startOfParagraph":true},{"content":"and dynamic memory allocation on the heap,","startTime":317000,"duration":4000,"startOfParagraph":false},{"content":"checking for null whenever you have a function that might ","startTime":321000,"duration":4000,"startOfParagraph":false},{"content":"return null as a value is something that you'll want to get in the habit of doing.","startTime":325000,"duration":5000,"startOfParagraph":false},{"content":"This is here primarily for illustration.","startTime":330000,"duration":3000,"startOfParagraph":false},{"content":"But when you do see GetString in the future, ","startTime":333000,"duration":3000,"startOfParagraph":false},{"content":"so from Problem Set 4 on, you'll want to keep this in mind.","startTime":336000,"duration":5000,"startOfParagraph":false},{"content":"Again, this is not an issue for Problem Set 3 either since we hadn't covered it yet.","startTime":341000,"duration":3000,"startOfParagraph":false},{"content":"Finally, we get to this part where we get to the main encryption loop,","startTime":344000,"duration":9000,"startOfParagraph":false},{"content":"and there are a couple of things going on here.","startTime":353000,"duration":4000,"startOfParagraph":false},{"content":"First, we iterate over the entire message string itself.","startTime":357000,"duration":5000,"startOfParagraph":false},{"content":"Here we've kept the strlen call in the condition,","startTime":362000,"duration":5000,"startOfParagraph":false},{"content":"which a number of you have pointed out is not a great way to go.","startTime":367000,"duration":5000,"startOfParagraph":false},{"content":"It turns out in this case it's also not great, ","startTime":372000,"duration":3000,"startOfParagraph":false},{"content":"partly because we're modifying the contents of the message itself","startTime":375000,"duration":5000,"startOfParagraph":false},{"content":"inside the for loop, so if we have a message that's 10 characters long,","startTime":380000,"duration":7000,"startOfParagraph":false},{"content":"the first time we start that for loop strlen will return what?","startTime":387000,"duration":5000,"startOfParagraph":false},{"content":"10.","startTime":392000,"duration":3000,"startOfParagraph":false},{"content":"But if we then modify message, say we modify its 5th character,","startTime":395000,"duration":5000,"startOfParagraph":true},{"content":"and we throw in a \\0 character in the 5th position,","startTime":400000,"duration":6000,"startOfParagraph":false},{"content":"on a subsequent iteration strlen(message) won't return what it did","startTime":406000,"duration":3000,"startOfParagraph":false},{"content":"the very first time we iterated,","startTime":409000,"duration":3000,"startOfParagraph":false},{"content":"but it will instead return 5 because we threw in that null terminator, ","startTime":412000,"duration":4000,"startOfParagraph":false},{"content":"and the string's length is defined ","startTime":416000,"duration":3000,"startOfParagraph":false},{"content":"by the position of that \\0.","startTime":419000,"duration":4000,"startOfParagraph":false},{"content":"In this case, this is a great way to go because we're modifying it in place.","startTime":423000,"duration":6000,"startOfParagraph":false},{"content":"But you notice that this is actually surprisingly simple to encrypt","startTime":429000,"duration":4000,"startOfParagraph":false},{"content":"if you can get the math correct.","startTime":433000,"duration":3000,"startOfParagraph":false},{"content":"All that's required is to check whether or not the letter that you're looking at","startTime":436000,"duration":3000,"startOfParagraph":false},{"content":"is uppercase or lowercase.","startTime":439000,"duration":2000,"startOfParagraph":false},{"content":"The reason we only have to check for that and we don't have to check for","startTime":441000,"duration":3000,"startOfParagraph":true},{"content":"the is alpha case is because ","startTime":444000,"duration":3000,"startOfParagraph":false},{"content":"if a character is uppercase or if it's lowercase","startTime":447000,"duration":3000,"startOfParagraph":false},{"content":"then it's definitely an alphabetic character,","startTime":450000,"duration":3000,"startOfParagraph":false},{"content":"because we don't have uppercase and lowercase digits.","startTime":453000,"duration":5000,"startOfParagraph":false},{"content":"The other thing we do—and this is a little tricky—","startTime":458000,"duration":3000,"startOfParagraph":false},{"content":"is we've modified the standard Caesar cipher formula","startTime":461000,"duration":4000,"startOfParagraph":false},{"content":"that we gave in the problem set specification.","startTime":465000,"duration":4000,"startOfParagraph":false},{"content":"What's different here is that we subtracted","startTime":469000,"duration":3000,"startOfParagraph":false},{"content":"in the uppercase case capital A, and then we added capital A","startTime":472000,"duration":6000,"startOfParagraph":false},{"content":"back in at the end. ","startTime":478000,"duration":4000,"startOfParagraph":false},{"content":"I know a few of you have done this in your code.","startTime":482000,"duration":3000,"startOfParagraph":true},{"content":"Did any of you do this in your submissions?","startTime":485000,"duration":4000,"startOfParagraph":false},{"content":"You did this. Can you explain what this does, Sahb?","startTime":489000,"duration":4000,"startOfParagraph":false},{"content":"By subtracting it out, because you did a mod right after it,","startTime":493000,"duration":5000,"startOfParagraph":false},{"content":"you have to take it out, so that way you get [coughing] position.","startTime":498000,"duration":3000,"startOfParagraph":false},{"content":"And then by adding it back later you shifted over the one that you wanted.","startTime":501000,"duration":4000,"startOfParagraph":false},{"content":"Yeah, exactly.","startTime":505000,"duration":2000,"startOfParagraph":false},{"content":"What Sahb said was that when we want to add","startTime":507000,"duration":5000,"startOfParagraph":false},{"content":"our message and our key together","startTime":512000,"duration":4000,"startOfParagraph":false},{"content":"and then mod that, mod that by NUM_LETTERS,","startTime":516000,"duration":6000,"startOfParagraph":false},{"content":"if we don't scale our message into the appropriate 0 to 25 range first,","startTime":522000,"duration":8000,"startOfParagraph":false},{"content":"then we might end up getting a really weird number","startTime":530000,"duration":4000,"startOfParagraph":false},{"content":"because the values that we're looking at when we look at message[i],","startTime":534000,"duration":5000,"startOfParagraph":false},{"content":"when we look at the ith character of our plain-text message,","startTime":539000,"duration":4000,"startOfParagraph":false},{"content":"is a value somewhere in this 65 to 122 range","startTime":543000,"duration":5000,"startOfParagraph":false},{"content":"based on the ASCII values for uppercase A through lowercase z.","startTime":548000,"duration":5000,"startOfParagraph":false},{"content":"And so when we mod it by 26 or by NUM_LETTERS, ","startTime":553000,"duration":5000,"startOfParagraph":false},{"content":"since that was our #define at the top right up here,","startTime":558000,"duration":5000,"startOfParagraph":false},{"content":"that's going to give us a value that's in the 0 to 25 range,","startTime":563000,"duration":5000,"startOfParagraph":false},{"content":"and we need a way to then scale that back up","startTime":568000,"duration":2000,"startOfParagraph":false},{"content":"and get it in the appropriate ASCII range.","startTime":570000,"duration":2000,"startOfParagraph":false},{"content":"The easiest way to do that is to just scale everything down","startTime":572000,"duration":4000,"startOfParagraph":false},{"content":"into the 0 to 25 range to begin with,","startTime":576000,"duration":3000,"startOfParagraph":false},{"content":"and then shift everything back up at the end.","startTime":579000,"duration":4000,"startOfParagraph":false},{"content":"Another common error that I saw people run into is that","startTime":583000,"duration":3000,"startOfParagraph":true},{"content":"if you don't actually do this scaling right away","startTime":586000,"duration":4000,"startOfParagraph":false},{"content":"and you add message and key together and you add them, say,","startTime":590000,"duration":3000,"startOfParagraph":false},{"content":"into a char variable, the problem with that","startTime":593000,"duration":5000,"startOfParagraph":false},{"content":"is since message[i] is a relatively big number to begin with—","startTime":598000,"duration":3000,"startOfParagraph":false},{"content":"remember it's at least 65 if it's an uppercase character—","startTime":601000,"duration":4000,"startOfParagraph":false},{"content":"if you have a large key, say, something like 100,","startTime":605000,"duration":4000,"startOfParagraph":false},{"content":"and you add those 2 together into a signed char you're going to get an overflow.","startTime":609000,"duration":4000,"startOfParagraph":false},{"content":"You're going to get a value that's larger than 127,","startTime":613000,"duration":4000,"startOfParagraph":false},{"content":"which is the largest value that a char variable can hold.","startTime":617000,"duration":5000,"startOfParagraph":false},{"content":"Again, that's why you'd want to do that sort of thing to begin with.","startTime":622000,"duration":4000,"startOfParagraph":false},{"content":"Some people got around that case by doing an if else and testing ","startTime":626000,"duration":3000,"startOfParagraph":false},{"content":"to see if it would overflow before doing that,","startTime":629000,"duration":4000,"startOfParagraph":false},{"content":"but this way gets around that.","startTime":633000,"duration":3000,"startOfParagraph":false},{"content":"And then in this solution we printed out the whole string at the very end.","startTime":636000,"duration":4000,"startOfParagraph":false},{"content":"Other people printed out a character at a time. Both are awesome.","startTime":640000,"duration":5000,"startOfParagraph":false},{"content":"At this point, do you guys have any questions, any comments about this?","startTime":645000,"duration":6000,"startOfParagraph":false},{"content":"Things you like, things you don't like?","startTime":651000,"duration":5000,"startOfParagraph":false},{"content":"I had a question. ","startTime":656000,"duration":2000,"startOfParagraph":true},{"content":"Maybe I missed it during your explanation, but how does this program","startTime":658000,"duration":3000,"startOfParagraph":false},{"content":"skip the spaces for connecting the key to the length of the text?","startTime":661000,"duration":6000,"startOfParagraph":false},{"content":"This is just Caesar cipher.>>Oh, sorry, yeah.","startTime":667000,"duration":3000,"startOfParagraph":false},{"content":"Yeah, we'll see that.","startTime":670000,"duration":3000,"startOfParagraph":false},{"content":"In the Caesar cipher we got around that because ","startTime":673000,"duration":3000,"startOfParagraph":false},{"content":"we only flipped characters.","startTime":676000,"duration":2000,"startOfParagraph":false},{"content":"We only rotated them if they were uppercase or lowercase.","startTime":678000,"duration":9000,"startOfParagraph":false},{"content":"You guys feeling pretty good about this?","startTime":687000,"duration":5000,"startOfParagraph":false},{"content":"Feel free to copy this home, take it, ","startTime":692000,"duration":2000,"startOfParagraph":false},{"content":"compare it to what you guys wrote.","startTime":694000,"duration":3000,"startOfParagraph":false},{"content":"Definitely feel free to send questions about it too.","startTime":697000,"duration":5000,"startOfParagraph":false},{"content":"And again, realize that the goal here with your problem sets","startTime":702000,"duration":4000,"startOfParagraph":false},{"content":"is not to get you guys to write perfect code for your problem sets.","startTime":706000,"duration":4000,"startOfParagraph":false},{"content":"It's a learning experience. Yeah.","startTime":710000,"duration":7000,"startOfParagraph":false},{"content":"Back to the do while loop, if it equals null,","startTime":717000,"duration":4000,"startOfParagraph":true},{"content":"so null just means nothing, they just hit enter?","startTime":721000,"duration":5000,"startOfParagraph":false},{"content":"Null is a special pointer value,","startTime":726000,"duration":6000,"startOfParagraph":false},{"content":"and we use null when we want to say ","startTime":732000,"duration":5000,"startOfParagraph":false},{"content":"we have a pointer variable that is pointing to nothing.","startTime":737000,"duration":6000,"startOfParagraph":false},{"content":"And so typically it means that this variable, this message variable","startTime":743000,"duration":5000,"startOfParagraph":false},{"content":"is empty, and here, because we're using the CS50 special string type,","startTime":748000,"duration":7000,"startOfParagraph":false},{"content":"what is the CS50 string type?","startTime":755000,"duration":2000,"startOfParagraph":false},{"content":"Have you seen what it is when David pulled back the hood in lecture?","startTime":757000,"duration":5000,"startOfParagraph":false},{"content":"It's a funky—it's a pointer, right?","startTime":762000,"duration":2000,"startOfParagraph":false},{"content":"Okay, yeah.>>It's a char*.","startTime":764000,"duration":4000,"startOfParagraph":false},{"content":"And so really we could replace this","startTime":768000,"duration":4000,"startOfParagraph":false},{"content":"right here with char* message,","startTime":772000,"duration":4000,"startOfParagraph":false},{"content":"and so the GetString function, if it doesn't successfully get a string from the user,","startTime":776000,"duration":8000,"startOfParagraph":false},{"content":"it can't parse a string, and the one case in which it can't parse a string","startTime":784000,"duration":4000,"startOfParagraph":false},{"content":"is if the user types the end of file character, the control D,","startTime":788000,"duration":3000,"startOfParagraph":false},{"content":"which is not something you typically do, but if that happens","startTime":791000,"duration":6000,"startOfParagraph":false},{"content":"then the function will return this null value as a way of saying","startTime":797000,"duration":3000,"startOfParagraph":false},{"content":"\"Hey, I didn't get a string.\"","startTime":800000,"duration":3000,"startOfParagraph":false},{"content":"What would happen if we don't put message = null,","startTime":803000,"duration":4000,"startOfParagraph":false},{"content":"which is something that we haven't been doing yet?","startTime":807000,"duration":3000,"startOfParagraph":false},{"content":"Why would that be a problem here?","startTime":810000,"duration":2000,"startOfParagraph":false},{"content":"Because I know that we talked a little bit in lecture about memory leaks.","startTime":812000,"duration":6000,"startOfParagraph":false},{"content":"Yeah, let's do that, and let's see what happens.","startTime":818000,"duration":4000,"startOfParagraph":false},{"content":"Basil's question was what happens if we don't actually have","startTime":822000,"duration":2000,"startOfParagraph":true},{"content":"this message = null test?","startTime":824000,"duration":4000,"startOfParagraph":false},{"content":"Let's scroll up to the top.","startTime":828000,"duration":3000,"startOfParagraph":false},{"content":"You guys can comment this out.","startTime":831000,"duration":2000,"startOfParagraph":false},{"content":"Actually, I'll save it in a revision.","startTime":833000,"duration":2000,"startOfParagraph":false},{"content":"This will be Revision 3.","startTime":835000,"duration":3000,"startOfParagraph":false},{"content":"What you'll have to do to run this program is you'll have to click this gear icon up here,","startTime":838000,"duration":4000,"startOfParagraph":false},{"content":"and you'll have to add an argument to it.","startTime":842000,"duration":2000,"startOfParagraph":false},{"content":"You'll have to give it the key argument since we want to pass in a command line argument.","startTime":844000,"duration":6000,"startOfParagraph":false},{"content":"Here I'm going to give it the number 3. I like 3.","startTime":850000,"duration":3000,"startOfParagraph":false},{"content":"Now zooming back out, running the program.","startTime":853000,"duration":6000,"startOfParagraph":false},{"content":"It's running, compiling, building.","startTime":859000,"duration":5000,"startOfParagraph":false},{"content":"Here we go. It's waiting to be prompted.","startTime":864000,"duration":3000,"startOfParagraph":false},{"content":"If I type in something like hello—where did that go?","startTime":867000,"duration":6000,"startOfParagraph":false},{"content":"Oh, my program took too long to run. I was jawing for too long.","startTime":873000,"duration":5000,"startOfParagraph":false},{"content":"Here it goes. ","startTime":878000,"duration":2000,"startOfParagraph":false},{"content":"Now I type in hello.","startTime":880000,"duration":3000,"startOfParagraph":false},{"content":"We see that it encrypts appropriately.","startTime":883000,"duration":3000,"startOfParagraph":false},{"content":"Now what happens if we do prompt GetString to return null?","startTime":886000,"duration":6000,"startOfParagraph":false},{"content":"Remember, I said that we did that by pressing control D at the same time.","startTime":892000,"duration":5000,"startOfParagraph":false},{"content":"I'll scroll up here. We'll run it again.","startTime":897000,"duration":2000,"startOfParagraph":false},{"content":"Building. There it goes.","startTime":899000,"duration":2000,"startOfParagraph":false},{"content":"Now when I hit control D ","startTime":901000,"duration":3000,"startOfParagraph":false},{"content":"I got this line that says opt/sandbox50/bin/run.sh, Segmentation fault.","startTime":904000,"duration":8000,"startOfParagraph":false},{"content":"Have you guys seen that before?","startTime":912000,"duration":3000,"startOfParagraph":false},{"content":"[Student] Why is there no—>>Sorry?","startTime":915000,"duration":2000,"startOfParagraph":true},{"content":"[Student] Why is there no core dump in this case?","startTime":917000,"duration":3000,"startOfParagraph":false},{"content":"The core dump is—the question is why is there no core dump here?","startTime":920000,"duration":6000,"startOfParagraph":false},{"content":"The question is that there may be, but the core dump is a file","startTime":926000,"duration":3000,"startOfParagraph":false},{"content":"that gets stored on the hard drive.","startTime":929000,"duration":2000,"startOfParagraph":false},{"content":"In this case we've disabled core dumps","startTime":931000,"duration":3000,"startOfParagraph":false},{"content":"on the run server so that we don't have people seg faulting","startTime":934000,"duration":3000,"startOfParagraph":false},{"content":"and building up tons of core dumps.","startTime":937000,"duration":3000,"startOfParagraph":false},{"content":"But you may get one.","startTime":940000,"duration":6000,"startOfParagraph":false},{"content":"Core dumps are the sort of thing that you can often disable,","startTime":946000,"duration":2000,"startOfParagraph":false},{"content":"and sometimes you do.","startTime":948000,"duration":4000,"startOfParagraph":false},{"content":"The segmentation fault, to answer your question, Basil, ","startTime":952000,"duration":3000,"startOfParagraph":false},{"content":"is saying that we tried to access a pointer","startTime":955000,"duration":5000,"startOfParagraph":false},{"content":"that wasn't set to point to anything.","startTime":960000,"duration":5000,"startOfParagraph":false},{"content":"Remember Binky in the video when Binky tries to ","startTime":965000,"duration":4000,"startOfParagraph":false},{"content":"go access a pointer that's not pointing to anything?","startTime":969000,"duration":3000,"startOfParagraph":false},{"content":"In this case I guess technically the pointer is pointing to something.","startTime":972000,"duration":4000,"startOfParagraph":false},{"content":"It's pointing to null, which is technically 0,","startTime":976000,"duration":4000,"startOfParagraph":false},{"content":"but that is defined to be in a segment that is not accessible","startTime":980000,"duration":5000,"startOfParagraph":false},{"content":"by your program, so you get a segmentation fault","startTime":985000,"duration":3000,"startOfParagraph":false},{"content":"because you're not accessing memory that's in a valid segment","startTime":988000,"duration":3000,"startOfParagraph":false},{"content":"like the heap segment or the stack segment or the data segment.","startTime":991000,"duration":7000,"startOfParagraph":false},{"content":"Cool. ","startTime":998000,"duration":2000,"startOfParagraph":false},{"content":"Any more questions about Caesar? ","startTime":1000000,"duration":8000,"startOfParagraph":false},{"content":"Let's move on. Let's look at Revision 2 really quickly.","startTime":1008000,"duration":3000,"startOfParagraph":true},{"content":"That's Vigenère.","startTime":1011000,"duration":9000,"startOfParagraph":false},{"content":"Here in Vigenère ","startTime":1020000,"duration":4000,"startOfParagraph":false},{"content":"we'll walk through this one pretty quickly because, again, ","startTime":1024000,"duration":2000,"startOfParagraph":false},{"content":"Vigenère and Caesar are quite similar.","startTime":1026000,"duration":4000,"startOfParagraph":false},{"content":"Header comment is before,","startTime":1030000,"duration":2000,"startOfParagraph":false},{"content":"#define is before to avoid using these magic numbers.","startTime":1032000,"duration":5000,"startOfParagraph":false},{"content":"The nice thing is say we wanted to move to ","startTime":1037000,"duration":4000,"startOfParagraph":false},{"content":"a different alphabet or something like that.","startTime":1041000,"duration":2000,"startOfParagraph":false},{"content":"Rather than having to go manually change all the 26's in the code","startTime":1043000,"duration":3000,"startOfParagraph":false},{"content":"we could change this to 27 or drop it down","startTime":1046000,"duration":4000,"startOfParagraph":false},{"content":"if we were using different alphabets, different languages.","startTime":1050000,"duration":4000,"startOfParagraph":false},{"content":"Again, we've got this check of the argument count,","startTime":1054000,"duration":4000,"startOfParagraph":false},{"content":"and really you can almost take this as a template.","startTime":1058000,"duration":4000,"startOfParagraph":false},{"content":"Pretty much every program you write should have—","startTime":1062000,"duration":4000,"startOfParagraph":false},{"content":"if it takes command line arguments—some sequence of lines","startTime":1066000,"duration":4000,"startOfParagraph":false},{"content":"that reads like this at the very beginning.","startTime":1070000,"duration":5000,"startOfParagraph":false},{"content":"That's one of the first sanity tests you want to do.","startTime":1075000,"duration":4000,"startOfParagraph":false},{"content":"Here what we did was we made sure that ","startTime":1079000,"duration":4000,"startOfParagraph":true},{"content":"the keyword was valid, and that was the second check that we did.","startTime":1083000,"duration":3000,"startOfParagraph":false},{"content":"Notice again that we separated this from argc and 2.","startTime":1086000,"duration":5000,"startOfParagraph":false},{"content":"Note that in this case one thing that we had to do was instead","startTime":1091000,"duration":3000,"startOfParagraph":false},{"content":"of using a to i we wanted to validate the entire string,","startTime":1094000,"duration":4000,"startOfParagraph":false},{"content":"and in order to do that you actually have to go character by character","startTime":1098000,"duration":3000,"startOfParagraph":false},{"content":"over the string. ","startTime":1101000,"duration":2000,"startOfParagraph":false},{"content":"There's no good way to call something on it","startTime":1103000,"duration":6000,"startOfParagraph":false},{"content":"because even, for example, a to i will return 0 ","startTime":1109000,"duration":2000,"startOfParagraph":false},{"content":"if it can't parse an integer, so that doesn't even work.","startTime":1111000,"duration":6000,"startOfParagraph":false},{"content":"Again, nice message telling the user exactly what happened.","startTime":1117000,"duration":5000,"startOfParagraph":false},{"content":"Then here, again, we also handle the case where","startTime":1122000,"duration":3000,"startOfParagraph":false},{"content":"the user types in a control D random character.","startTime":1125000,"duration":5000,"startOfParagraph":false},{"content":"And then Charlotte had a question earlier about how we manage to skip spaces","startTime":1130000,"duration":4000,"startOfParagraph":true},{"content":"in our string here.","startTime":1134000,"duration":3000,"startOfParagraph":false},{"content":"This was kind of similar to what we did with the Myspace program","startTime":1137000,"duration":3000,"startOfParagraph":false},{"content":"that we did in section, and the way this worked","startTime":1140000,"duration":4000,"startOfParagraph":false},{"content":"is that we tracked the number of letters that we'd seen.","startTime":1144000,"duration":4000,"startOfParagraph":false},{"content":"As we walked over the message string, as we walked over character by character,","startTime":1148000,"duration":5000,"startOfParagraph":false},{"content":"we tracked the index as part of our for loop, and then we also tracked ","startTime":1153000,"duration":3000,"startOfParagraph":false},{"content":"the number of letters, so non-special characters, non-digits, non-white space","startTime":1156000,"duration":5000,"startOfParagraph":false},{"content":"that we'd seen in the separate variable.","startTime":1161000,"duration":6000,"startOfParagraph":false},{"content":"And then this solution modifies the key","startTime":1167000,"duration":6000,"startOfParagraph":false},{"content":"to get an actual key integer, and it does that on the fly,","startTime":1173000,"duration":8000,"startOfParagraph":false},{"content":"right before it then goes to encrypt the actual message character.","startTime":1181000,"duration":6000,"startOfParagraph":false},{"content":"There are some solutions that were perfectly great too","startTime":1187000,"duration":3000,"startOfParagraph":false},{"content":"that would modify the key up when testing for the key's validity.","startTime":1190000,"duration":8000,"startOfParagraph":false},{"content":"In addition to making sure that the character and the keyword","startTime":1198000,"duration":3000,"startOfParagraph":false},{"content":"was an alphabetic character it also turned that into an integer","startTime":1201000,"duration":4000,"startOfParagraph":false},{"content":"in the 0 to 25 range to then skip having to do that later on in this for loop.","startTime":1205000,"duration":8000,"startOfParagraph":false},{"content":"Again, you see here this is really the exact same code","startTime":1213000,"duration":5000,"startOfParagraph":false},{"content":"that we used in Caesar at this point.","startTime":1218000,"duration":4000,"startOfParagraph":false},{"content":"You're doing the exact same thing, so the real trick is figuring out","startTime":1222000,"duration":3000,"startOfParagraph":false},{"content":"how to turn the keyword into an integer.","startTime":1225000,"duration":5000,"startOfParagraph":false},{"content":"One thing that we did here that is a little dense","startTime":1230000,"duration":5000,"startOfParagraph":true},{"content":"is we repeated this phrase, I guess you could call it,","startTime":1235000,"duration":4000,"startOfParagraph":false},{"content":"3 separate times on lines 58, 59, and 61.","startTime":1239000,"duration":6000,"startOfParagraph":false},{"content":"Can somebody explain what exactly this phrase does?","startTime":1245000,"duration":7000,"startOfParagraph":false},{"content":"It's accessing a character, like you said.","startTime":1252000,"duration":3000,"startOfParagraph":false},{"content":"Yeah, it's [inaudible] a character in the keyword,","startTime":1255000,"duration":4000,"startOfParagraph":false},{"content":"and so it's number of letters seen because you're only moving along ","startTime":1259000,"duration":5000,"startOfParagraph":false},{"content":"the keyword once you've seen the letter,","startTime":1264000,"duration":2000,"startOfParagraph":false},{"content":"so that's going to effectively skip spaces and stuff like that.","startTime":1266000,"duration":4000,"startOfParagraph":false},{"content":"Yeah, exactly.","startTime":1270000,"duration":2000,"startOfParagraph":false},{"content":"And then once you've seen the keyword blank you just mod so you move back around.","startTime":1272000,"duration":4000,"startOfParagraph":false},{"content":"Exactly. That's a perfect explanation.","startTime":1276000,"duration":2000,"startOfParagraph":false},{"content":"What Kevin said is that we want to index into the keyword.","startTime":1278000,"duration":5000,"startOfParagraph":false},{"content":"We want to get the num_letters_seen character, if you will,","startTime":1283000,"duration":5000,"startOfParagraph":false},{"content":"but if num_letters_seen exceeds the length of the keyword,","startTime":1288000,"duration":4000,"startOfParagraph":false},{"content":"the way we get back into the appropriate range is we use the mod operator","startTime":1292000,"duration":5000,"startOfParagraph":false},{"content":"to effectively wrap around.","startTime":1297000,"duration":3000,"startOfParagraph":false},{"content":"For example, like in the short, our keyword is bacon,","startTime":1300000,"duration":3000,"startOfParagraph":false},{"content":"and it's 5 letters long.","startTime":1303000,"duration":3000,"startOfParagraph":false},{"content":"But we've seen 6 letters in our plain text at this point","startTime":1306000,"duration":4000,"startOfParagraph":false},{"content":"and encrypted 6.","startTime":1310000,"duration":2000,"startOfParagraph":false},{"content":"We will end up accessing the num_letters_seen,","startTime":1312000,"duration":5000,"startOfParagraph":false},{"content":"which is 6, mod the length of the keyword, 5, ","startTime":1317000,"duration":3000,"startOfParagraph":false},{"content":"and so we'll get 1, and so what we'll do is we'll","startTime":1320000,"duration":4000,"startOfParagraph":false},{"content":"access the first character inside of our keyword at that point.","startTime":1324000,"duration":10000,"startOfParagraph":false},{"content":"All right, any questions on Vigenère","startTime":1334000,"duration":7000,"startOfParagraph":true},{"content":"before we move on?","startTime":1341000,"duration":5000,"startOfParagraph":false},{"content":"You guys feeling pretty good about this?","startTime":1346000,"duration":5000,"startOfParagraph":false},{"content":"Cool, great.","startTime":1351000,"duration":4000,"startOfParagraph":false},{"content":"I want to make sure that you guys are getting the chance to see code","startTime":1355000,"duration":3000,"startOfParagraph":false},{"content":"that we think looks good and have the chance to learn from it.","startTime":1358000,"duration":10000,"startOfParagraph":false},{"content":"This is going to be the last we'll be using spaces for the time being,","startTime":1368000,"duration":5000,"startOfParagraph":false},{"content":"and we're going to transition now, and I'm going to go to cs50.net/lectures","startTime":1373000,"duration":6000,"startOfParagraph":false},{"content":"so we can do a little bit of quiz review.","startTime":1379000,"duration":7000,"startOfParagraph":false},{"content":"The best way I think to start doing quiz review","startTime":1386000,"duration":4000,"startOfParagraph":false},{"content":"is to come to this Lectures page, cs50.net/lectures,","startTime":1390000,"duration":5000,"startOfParagraph":false},{"content":"and underneath each of the week headings, so if I look here at Week 0,","startTime":1395000,"duration":5000,"startOfParagraph":false},{"content":"I see that we have a list of topics that we covered in Week 0.","startTime":1400000,"duration":7000,"startOfParagraph":false},{"content":"If any of these topics seem unfamiliar to you","startTime":1407000,"duration":4000,"startOfParagraph":true},{"content":"you'll definitely want to go back and scour the lecture notes and possibly ","startTime":1411000,"duration":3000,"startOfParagraph":false},{"content":"even skim through the lectures, watch them again if you want","startTime":1414000,"duration":5000,"startOfParagraph":false},{"content":"to get a feel for what's going on with each of those topics.","startTime":1419000,"duration":5000,"startOfParagraph":false},{"content":"I will say additionally this year one of the cool resources we've got","startTime":1424000,"duration":5000,"startOfParagraph":false},{"content":"is these shorts that we've created, and if you look at Week 0,","startTime":1429000,"duration":6000,"startOfParagraph":false},{"content":"we don't have all of the topics covered, but we've got quite a few of them,","startTime":1435000,"duration":5000,"startOfParagraph":false},{"content":"some of the trickier ones, so watching these shorts again","startTime":1440000,"duration":3000,"startOfParagraph":false},{"content":"is a good way to get you up to speed.","startTime":1443000,"duration":5000,"startOfParagraph":false},{"content":"In particular, I'm going to put in a plug for the 3 on the bottom, since I did those.","startTime":1448000,"duration":7000,"startOfParagraph":false},{"content":"But if you're struggling with binary, bits, hex, that kind of stuff,","startTime":1455000,"duration":5000,"startOfParagraph":false},{"content":"binary is a great place to start.","startTime":1460000,"duration":2000,"startOfParagraph":false},{"content":"ASCII is another one that's good to view too.","startTime":1462000,"duration":3000,"startOfParagraph":false},{"content":"You can even watch me at 1.5x speed if I'm going too slow for you.","startTime":1465000,"duration":6000,"startOfParagraph":false},{"content":"Since it's review, feel free to do that.","startTime":1471000,"duration":4000,"startOfParagraph":false},{"content":"Just to start really quickly, we're going to go through a couple of these quiz problems","startTime":1475000,"duration":5000,"startOfParagraph":true},{"content":"just to quickly churn through these.","startTime":1480000,"duration":4000,"startOfParagraph":false},{"content":"For example, let's look at problem 16 that I've got right up here on the board.","startTime":1484000,"duration":6000,"startOfParagraph":false},{"content":"We've got this following calculation in binary,","startTime":1490000,"duration":4000,"startOfParagraph":false},{"content":"and we want to show any work.","startTime":1494000,"duration":2000,"startOfParagraph":false},{"content":"Okay, I'm going to give this a shot.","startTime":1496000,"duration":3000,"startOfParagraph":false},{"content":"You guys should follow along with paper,","startTime":1499000,"duration":2000,"startOfParagraph":false},{"content":"and we'll do this really quickly.","startTime":1501000,"duration":3000,"startOfParagraph":false},{"content":"We want to perform the following calculation in binary.","startTime":1504000,"duration":2000,"startOfParagraph":false},{"content":"I've got 00110010.","startTime":1506000,"duration":10000,"startOfParagraph":false},{"content":"And I'm going to add to it 00110010.","startTime":1516000,"duration":11000,"startOfParagraph":false},{"content":"For the math geniuses following along at home,","startTime":1527000,"duration":3000,"startOfParagraph":false},{"content":"this is effectively multiplying by 2.","startTime":1530000,"duration":5000,"startOfParagraph":false},{"content":"Let's start.","startTime":1535000,"duration":2000,"startOfParagraph":false},{"content":"We're going to follow the same addition algorithm that we do","startTime":1537000,"duration":2000,"startOfParagraph":false},{"content":"when we add decimal numbers together.","startTime":1539000,"duration":4000,"startOfParagraph":false},{"content":"Really the only difference here is that we loop back around","startTime":1543000,"duration":3000,"startOfParagraph":false},{"content":"once we have 1 + 1 instead of once we get to 10.","startTime":1546000,"duration":5000,"startOfParagraph":false},{"content":"If we start from the right, really quickly, what's the first digit?","startTime":1551000,"duration":2000,"startOfParagraph":true},{"content":"[Student] 0.>>[Nate H.] 0.","startTime":1553000,"duration":2000,"startOfParagraph":false},{"content":"Great, the second digit?","startTime":1555000,"duration":3000,"startOfParagraph":false},{"content":"[Student] 1.","startTime":1558000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] Is it a 1? 1 + 1 is?","startTime":1560000,"duration":2000,"startOfParagraph":false},{"content":"[Student] 10.","startTime":1562000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] Exactly, so what is the digit that I write right beneath the 2 ones added together?","startTime":1564000,"duration":4000,"startOfParagraph":false},{"content":"[Student] 1, 0, or 0 and then carry the 1.","startTime":1568000,"duration":3000,"startOfParagraph":false},{"content":"[Nate H.] 0 and carry a 1, exactly.","startTime":1571000,"duration":4000,"startOfParagraph":false},{"content":"Next one up, Basil, you're up.","startTime":1575000,"duration":3000,"startOfParagraph":false},{"content":"What's the third?>>[Basil] 1.","startTime":1578000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] 1, perfect. Kevin?","startTime":1580000,"duration":3000,"startOfParagraph":false},{"content":"[Kevin] 0.>>[Nate H.] 0, Charlotte?","startTime":1583000,"duration":4000,"startOfParagraph":false},{"content":"[Charlotte] 0.>>[Nate H.] Yeah, and what do I do?","startTime":1587000,"duration":3000,"startOfParagraph":false},{"content":"[Student] The 1.","startTime":1590000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] And what do I do? And then I carry the 1.","startTime":1592000,"duration":2000,"startOfParagraph":false},{"content":"Perfect, Sahb?>>[Sahb] Now you have 1.","startTime":1594000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] And do I do anything here?","startTime":1596000,"duration":4000,"startOfParagraph":false},{"content":"[Sahb] Then for the next one you have 1 because you carried over 1.","startTime":1600000,"duration":3000,"startOfParagraph":false},{"content":"[Nate H.] Great, so here we can finish it up.","startTime":1603000,"duration":6000,"startOfParagraph":false},{"content":"Cool.","startTime":1609000,"duration":2000,"startOfParagraph":false},{"content":"[Student] Does 0 + 0 = 0?","startTime":1611000,"duration":3000,"startOfParagraph":false},{"content":"0 + 0 = 0.","startTime":1614000,"duration":2000,"startOfParagraph":false},{"content":"1 + 1, like you said, is 10, or 1, 0, rather.","startTime":1616000,"duration":5000,"startOfParagraph":false},{"content":"10 is a misnomer because to me 10 means the number 10,","startTime":1621000,"duration":6000,"startOfParagraph":false},{"content":"and it's the quirk of how we're representing it when we're writing it.","startTime":1627000,"duration":5000,"startOfParagraph":false},{"content":"We represent the number 2 by 1, 0, and the number 10 is slightly different.","startTime":1632000,"duration":8000,"startOfParagraph":false},{"content":"What's kind of nice about binary is that there really aren't that many ","startTime":1640000,"duration":3000,"startOfParagraph":true},{"content":"cases you need to learn.","startTime":1643000,"duration":2000,"startOfParagraph":false},{"content":"There's 0 + 0 = 0, 0 + 1 = 1,","startTime":1645000,"duration":5000,"startOfParagraph":false},{"content":"1 + 1 is 0, and then carry a 1, ","startTime":1650000,"duration":4000,"startOfParagraph":false},{"content":"and then you can see here on the third column from the right","startTime":1654000,"duration":3000,"startOfParagraph":false},{"content":"we had this 1, 1, and 1.","startTime":1657000,"duration":3000,"startOfParagraph":false},{"content":"And 1 + 1 + 1 is a 1, ","startTime":1660000,"duration":3000,"startOfParagraph":false},{"content":"and you carry another 1.","startTime":1663000,"duration":2000,"startOfParagraph":false},{"content":"When you're doing binary addition, pretty simple.","startTime":1665000,"duration":3000,"startOfParagraph":false},{"content":"I'd do a couple more of these to sanity check yourselves","startTime":1668000,"duration":3000,"startOfParagraph":false},{"content":"before you go in because this is ","startTime":1671000,"duration":3000,"startOfParagraph":false},{"content":"probably something that we'll see on the quiz.","startTime":1674000,"duration":6000,"startOfParagraph":false},{"content":"Now let's do this next one as well.","startTime":1680000,"duration":3000,"startOfParagraph":false},{"content":"Let's do problem 17.","startTime":1683000,"duration":3000,"startOfParagraph":false},{"content":"We're going to convert the following binary number to decimal.","startTime":1686000,"duration":6000,"startOfParagraph":false},{"content":"I've got 10100111001.","startTime":1692000,"duration":16000,"startOfParagraph":false},{"content":"Remember in the binary video that I did","startTime":1708000,"duration":5000,"startOfParagraph":false},{"content":"I walked through a couple of examples, and I showed how","startTime":1713000,"duration":3000,"startOfParagraph":false},{"content":"everything works when you're doing it in decimal.","startTime":1716000,"duration":5000,"startOfParagraph":false},{"content":"When you're working in decimal representation I think we're","startTime":1721000,"duration":4000,"startOfParagraph":false},{"content":"at this point in our lives so fluent in it that","startTime":1725000,"duration":3000,"startOfParagraph":false},{"content":"it's pretty easy to gloss over the mechanics of how it actually works.","startTime":1728000,"duration":5000,"startOfParagraph":false},{"content":"But to do a quick recap, if I have the number 137","startTime":1733000,"duration":6000,"startOfParagraph":true},{"content":"this really means—and again, this is in decimal representation—","startTime":1739000,"duration":7000,"startOfParagraph":false},{"content":"the number 137 in decimal means that I have 1 x 100 + 3 x 10 + 7 x 1.","startTime":1746000,"duration":13000,"startOfParagraph":false},{"content":"This is all staying on the screen.","startTime":1759000,"duration":3000,"startOfParagraph":false},{"content":"And then if you look at these numbers right here, ","startTime":1762000,"duration":7000,"startOfParagraph":false},{"content":"100, 10 and 1, you see that they're actually all powers of 10.","startTime":1769000,"duration":5000,"startOfParagraph":false},{"content":"I have 10², 10¹, and 10 to the zero. ","startTime":1774000,"duration":9000,"startOfParagraph":false},{"content":"We have a similar sort of thing in binary,","startTime":1783000,"duration":5000,"startOfParagraph":false},{"content":"except that our base, as we call it, is 2 instead of 10.","startTime":1788000,"duration":7000,"startOfParagraph":false},{"content":"These 10s that I wrote down here at the bottom, ","startTime":1795000,"duration":3000,"startOfParagraph":false},{"content":"this 10², 10¹, 10 to the zero, 10 is our base,","startTime":1798000,"duration":4000,"startOfParagraph":false},{"content":"and the exponent, 0, 1, or 2,","startTime":1802000,"duration":6000,"startOfParagraph":false},{"content":"is implied by the position of the digit in the number that we write.","startTime":1808000,"duration":6000,"startOfParagraph":false},{"content":"1, if we look at it, this 1 is in the 2nd position.","startTime":1814000,"duration":7000,"startOfParagraph":false},{"content":"The 3 is in the 1st position, and the 7 is in the 0th position.","startTime":1821000,"duration":6000,"startOfParagraph":false},{"content":"That's how we get the various exponents below for our bases.","startTime":1827000,"duration":8000,"startOfParagraph":false},{"content":"Following all of this we'll—actually, you know what?","startTime":1835000,"duration":5000,"startOfParagraph":true},{"content":"We'll do—where did my undo button go?","startTime":1840000,"duration":3000,"startOfParagraph":false},{"content":"There it goes.","startTime":1843000,"duration":2000,"startOfParagraph":false},{"content":"I love this undo thing.","startTime":1845000,"duration":2000,"startOfParagraph":false},{"content":"Following this I think for me at least","startTime":1847000,"duration":4000,"startOfParagraph":false},{"content":"the easiest way to start converting a binary number","startTime":1851000,"duration":3000,"startOfParagraph":false},{"content":"or a hexadecimal number where the base is 16","startTime":1854000,"duration":3000,"startOfParagraph":false},{"content":"and not 10 or 2 is to go ahead and write out","startTime":1857000,"duration":5000,"startOfParagraph":false},{"content":"the bases and exponents for all of the numbers in my binary number at the top.","startTime":1862000,"duration":7000,"startOfParagraph":false},{"content":"If we start from left to right again, ","startTime":1869000,"duration":5000,"startOfParagraph":false},{"content":"which is kind of counterintuitive,","startTime":1874000,"duration":3000,"startOfParagraph":false},{"content":"I'll change back to black here, we have the 2 to the 0th position,","startTime":1877000,"duration":6000,"startOfParagraph":false},{"content":"and then we have 2¹, 2², ","startTime":1883000,"duration":4000,"startOfParagraph":false},{"content":"and then 2 to the 3, 2 to the 4, 2 to the 5, 6, ","startTime":1887000,"duration":6000,"startOfParagraph":false},{"content":"7, 8, 9, and 10.","startTime":1893000,"duration":6000,"startOfParagraph":false},{"content":"These numbers I've written out are all the exponents.","startTime":1899000,"duration":2000,"startOfParagraph":false},{"content":"I only wrote the bases here in the first 3 just for space.","startTime":1901000,"duration":7000,"startOfParagraph":false},{"content":"At this point I'm going to go ahead and I'm actually going to erase","startTime":1908000,"duration":2000,"startOfParagraph":true},{"content":"the stuff that we did in decimal, if that's okay.","startTime":1910000,"duration":3000,"startOfParagraph":false},{"content":"You've all got that.","startTime":1913000,"duration":4000,"startOfParagraph":false},{"content":"Those of you watching online I'm sure will be able to rewind me if you'd like.","startTime":1917000,"duration":8000,"startOfParagraph":false},{"content":"Switching back to the pen.","startTime":1925000,"duration":2000,"startOfParagraph":false},{"content":"Now, what we can do—if you guys aren't totally up to speed on your powers of 2,","startTime":1927000,"duration":5000,"startOfParagraph":false},{"content":"that's totally cool.","startTime":1932000,"duration":3000,"startOfParagraph":false},{"content":"It happens. I understand.","startTime":1935000,"duration":3000,"startOfParagraph":false},{"content":"I once had a job interview where I was told I should know all powers of 2","startTime":1938000,"duration":5000,"startOfParagraph":false},{"content":"up through 2 to the 30th.","startTime":1943000,"duration":3000,"startOfParagraph":false},{"content":"It was not a job I got.","startTime":1946000,"duration":3000,"startOfParagraph":false},{"content":"Anyway, you guys can go ahead and do the math here,","startTime":1949000,"duration":3000,"startOfParagraph":false},{"content":"but with binary it doesn't really make sense,","startTime":1952000,"duration":3000,"startOfParagraph":false},{"content":"and nor does it make sense with decimal or hexadecimal either,","startTime":1955000,"duration":3000,"startOfParagraph":false},{"content":"to do the math out where you have zeros.","startTime":1958000,"duration":5000,"startOfParagraph":false},{"content":"You can see I have 0 here, a 0 here, 0 here, 0 here, 0 here, 0 here.","startTime":1963000,"duration":6000,"startOfParagraph":false},{"content":"Why might it not make sense to do the actual math","startTime":1969000,"duration":3000,"startOfParagraph":false},{"content":"to calculate the appropriate power of 2 for that position?","startTime":1972000,"duration":4000,"startOfParagraph":false},{"content":"Exactly, like Charlotte said, it will be 0.","startTime":1976000,"duration":3000,"startOfParagraph":false},{"content":"Might as well save yourself the time if calculating powers of 2 isn't your strong suit.","startTime":1979000,"duration":6000,"startOfParagraph":false},{"content":"In this case we only need to calculate it for 2 to the 0 which is—?","startTime":1985000,"duration":5000,"startOfParagraph":false},{"content":"[Student] 1.","startTime":1990000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] 1, 2 to the 3 which is—?","startTime":1992000,"duration":2000,"startOfParagraph":false},{"content":"[Student] 8.>>[Nate H.] 8.","startTime":1994000,"duration":2000,"startOfParagraph":false},{"content":"2 to the 4?","startTime":1996000,"duration":2000,"startOfParagraph":false},{"content":"[Student] 2. I'm sorry, 1.","startTime":1998000,"duration":3000,"startOfParagraph":false},{"content":"[Nate H.] 2 to the 4 is 16, exactly.","startTime":2001000,"duration":5000,"startOfParagraph":false},{"content":"2 to the 5, Kevin?>>32.","startTime":2006000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] 32, 2 to the 8?","startTime":2008000,"duration":4000,"startOfParagraph":false},{"content":"[Student] 32 x 8, 256.","startTime":2012000,"duration":6000,"startOfParagraph":false},{"content":"[Nate H.] Perfect.","startTime":2018000,"duration":3000,"startOfParagraph":false},{"content":"And 2 to the 10?","startTime":2021000,"duration":2000,"startOfParagraph":false},{"content":"[Student] 1024.","startTime":2023000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] Yeah, 1024.","startTime":2025000,"duration":4000,"startOfParagraph":false},{"content":"Once we've got these numbers we can sum them all up.","startTime":2029000,"duration":8000,"startOfParagraph":true},{"content":"And this is where it's really important to do a couple of things.","startTime":2037000,"duration":4000,"startOfParagraph":false},{"content":"One is go slow and check your work.","startTime":2041000,"duration":6000,"startOfParagraph":false},{"content":"You can tell that there's a 1 at the end of this number, ","startTime":2047000,"duration":3000,"startOfParagraph":false},{"content":"so I should definitely get an odd number as my result,","startTime":2050000,"duration":5000,"startOfParagraph":false},{"content":"because all the other ones are going to be even numbers ","startTime":2055000,"duration":3000,"startOfParagraph":false},{"content":"given that it's a binary number.","startTime":2058000,"duration":3000,"startOfParagraph":false},{"content":"The other thing to do is if you get to this point on the test","startTime":2061000,"duration":3000,"startOfParagraph":false},{"content":"and you've written it out this far ","startTime":2064000,"duration":3000,"startOfParagraph":false},{"content":"and you're running out of time","startTime":2067000,"duration":3000,"startOfParagraph":false},{"content":"look at the number of points that this problem is worth.","startTime":2070000,"duration":3000,"startOfParagraph":false},{"content":"This problem, as you can see—if I flip back to my laptop really quickly—","startTime":2073000,"duration":7000,"startOfParagraph":false},{"content":"this problem is worth 2 points, so this is not the sort of addition ","startTime":2080000,"duration":4000,"startOfParagraph":false},{"content":"you should be going through if you're really pressed for time.","startTime":2084000,"duration":3000,"startOfParagraph":false},{"content":"But we'll switch back to the iPad, and we'll go through it really quickly.","startTime":2087000,"duration":5000,"startOfParagraph":false},{"content":"I like doing the small numbers first ","startTime":2092000,"duration":2000,"startOfParagraph":true},{"content":"because I find that easier. ","startTime":2094000,"duration":2000,"startOfParagraph":false},{"content":"I like 32 and 8 because they go together pretty easily, and we get 50.","startTime":2096000,"duration":4000,"startOfParagraph":false},{"content":"16 and 1 gets 17.","startTime":2100000,"duration":3000,"startOfParagraph":false},{"content":"There we get 57,","startTime":2103000,"duration":2000,"startOfParagraph":false},{"content":"and then we can do the rest of this, so we can do 57, 156.","startTime":2105000,"duration":9000,"startOfParagraph":false},{"content":"Come on. ","startTime":2114000,"duration":2000,"startOfParagraph":false},{"content":"Man, well, let's see.","startTime":2116000,"duration":3000,"startOfParagraph":false},{"content":"We had 57, 256, and 1024.","startTime":2119000,"duration":8000,"startOfParagraph":false},{"content":"At this point, I'd rather just go through.","startTime":2127000,"duration":4000,"startOfParagraph":false},{"content":"I have no clue. I clearly need to read up on this.","startTime":2131000,"duration":4000,"startOfParagraph":false},{"content":"7, 6, and 4, you get 17.","startTime":2135000,"duration":5000,"startOfParagraph":false},{"content":"1, 5, 5, 2, 13.","startTime":2140000,"duration":2000,"startOfParagraph":false},{"content":"Then we get 3, and then we get 1.","startTime":2142000,"duration":3000,"startOfParagraph":false},{"content":"1337.","startTime":2145000,"duration":7000,"startOfParagraph":false},{"content":"Easter egg, anybody?","startTime":2152000,"duration":3000,"startOfParagraph":false},{"content":"Anybody recognize this number?","startTime":2155000,"duration":4000,"startOfParagraph":false},{"content":"Chris recognizes the number. What does it mean, Chris?","startTime":2159000,"duration":3000,"startOfParagraph":false},{"content":"[Chris] Leet.","startTime":2162000,"duration":2000,"startOfParagraph":false},{"content":"Leet, so if you look at this, it looks like leet.","startTime":2164000,"duration":7000,"startOfParagraph":false},{"content":"Hacker stuff. Watch out for that kind of stuff on the midterm or the quiz, rather.","startTime":2171000,"duration":4000,"startOfParagraph":false},{"content":"If you see that kind of stuff and you're wondering \"Huh,\"","startTime":2175000,"duration":4000,"startOfParagraph":false},{"content":"that might actually mean something.","startTime":2179000,"duration":3000,"startOfParagraph":false},{"content":"I don't know. David likes putting it in.","startTime":2182000,"duration":2000,"startOfParagraph":false},{"content":"It's a good way to sanity check it.","startTime":2184000,"duration":2000,"startOfParagraph":false},{"content":"Like okay, I can see what's going on.","startTime":2186000,"duration":4000,"startOfParagraph":false},{"content":"That's Week 0/Week 1 stuff.","startTime":2190000,"duration":4000,"startOfParagraph":true},{"content":"If we switch back to our laptop now,","startTime":2194000,"duration":5000,"startOfParagraph":false},{"content":"zoom out, and a couple of other things.","startTime":2199000,"duration":7000,"startOfParagraph":false},{"content":"There's ASCII, which we've been doing a lot of with the problem sets.","startTime":2206000,"duration":4000,"startOfParagraph":false},{"content":"This notion of capital A. What is that really?","startTime":2210000,"duration":5000,"startOfParagraph":false},{"content":"Knowing it's the decimal integer.","startTime":2215000,"duration":2000,"startOfParagraph":false},{"content":"65 is what it's mapped to in the ASCII table,","startTime":2217000,"duration":3000,"startOfParagraph":false},{"content":"and that's therefore how the computer writes it,","startTime":2220000,"duration":3000,"startOfParagraph":false},{"content":"and that's how we've been getting away with actually writing","startTime":2223000,"duration":3000,"startOfParagraph":false},{"content":"the character capital A and the character lowercase a","startTime":2226000,"duration":3000,"startOfParagraph":false},{"content":"in some of these solutions and problem sets that you've been doing.","startTime":2229000,"duration":5000,"startOfParagraph":false},{"content":"A couple of other things.","startTime":2234000,"duration":2000,"startOfParagraph":false},{"content":"We've got statements, boolean expressions, conditions, loops, variables and threads.","startTime":2236000,"duration":9000,"startOfParagraph":false},{"content":"Those all seem to make sense for the most part?","startTime":2245000,"duration":4000,"startOfParagraph":true},{"content":"Some of this terminology is a little funky at times.","startTime":2249000,"duration":6000,"startOfParagraph":false},{"content":"I like to think of a statement as for the most part something that ends with a semicolon.","startTime":2255000,"duration":11000,"startOfParagraph":false},{"content":"Statements such as x = 7, which sets a variable, ","startTime":2266000,"duration":5000,"startOfParagraph":false},{"content":"presumably called x = 7.","startTime":2271000,"duration":3000,"startOfParagraph":false},{"content":"Presumably x is also a type that can store the number 7,","startTime":2274000,"duration":7000,"startOfParagraph":false},{"content":"so it's an int or possibly a float or a short or a char,","startTime":2281000,"duration":4000,"startOfParagraph":false},{"content":"something like that.","startTime":2285000,"duration":2000,"startOfParagraph":false},{"content":"A boolean expression is using these double equals","startTime":2287000,"duration":5000,"startOfParagraph":false},{"content":"and the bang equals or the not equals, less than, greater than, ","startTime":2292000,"duration":5000,"startOfParagraph":false},{"content":"less than or equal to, all that kind of stuff.","startTime":2297000,"duration":5000,"startOfParagraph":false},{"content":"Conditions then are if else statements.","startTime":2302000,"duration":6000,"startOfParagraph":false},{"content":"I would remember that you can't have an else without a corresponding if.","startTime":2308000,"duration":4000,"startOfParagraph":false},{"content":"Likewise, you can't have an else if without a corresponding if.","startTime":2312000,"duration":5000,"startOfParagraph":false},{"content":"Loops, recall the 3 kinds of loops we've been hammering into you ","startTime":2317000,"duration":3000,"startOfParagraph":false},{"content":"for the last couple of sections and problem sets.","startTime":2320000,"duration":3000,"startOfParagraph":false},{"content":"Using do while when you're getting user input, ","startTime":2323000,"duration":3000,"startOfParagraph":false},{"content":"using while loops until a particular condition is true,","startTime":2326000,"duration":5000,"startOfParagraph":false},{"content":"and then using those for loops if you need to","startTime":2331000,"duration":5000,"startOfParagraph":false},{"content":"know which iteration of the loop you're currently on is how I think about it.","startTime":2336000,"duration":5000,"startOfParagraph":false},{"content":"Or if you're doing a for each character in a string I want to do something,","startTime":2341000,"duration":6000,"startOfParagraph":false},{"content":"for each element in an array I want to do something to that element.","startTime":2347000,"duration":8000,"startOfParagraph":false},{"content":"Threads and events.","startTime":2355000,"duration":3000,"startOfParagraph":true},{"content":"These we haven't covered so explicitly in C,","startTime":2358000,"duration":3000,"startOfParagraph":false},{"content":"but remember this from Scratch.","startTime":2361000,"duration":2000,"startOfParagraph":false},{"content":"This is the notion of having different scripts.","startTime":2363000,"duration":3000,"startOfParagraph":false},{"content":"This is also this notion of broadcasting an event.","startTime":2366000,"duration":6000,"startOfParagraph":false},{"content":"Some people didn't use broadcasting in their projects initially, ","startTime":2372000,"duration":5000,"startOfParagraph":false},{"content":"which is totally cool, ","startTime":2377000,"duration":3000,"startOfParagraph":false},{"content":"but these are 2 different ways of handling this larger issue called concurrency,","startTime":2380000,"duration":6000,"startOfParagraph":false},{"content":"which is how do you get programs to execute ","startTime":2386000,"duration":3000,"startOfParagraph":false},{"content":"or seemingly execute at the same time?","startTime":2389000,"duration":5000,"startOfParagraph":false},{"content":"Different tasks running while other tasks are also running.","startTime":2394000,"duration":5000,"startOfParagraph":false},{"content":"This is how your operating system seems to work.","startTime":2399000,"duration":2000,"startOfParagraph":false},{"content":"This is why even though, for example, ","startTime":2401000,"duration":3000,"startOfParagraph":false},{"content":"I've got my browser running, I can also turn on Spotify and play a song.","startTime":2404000,"duration":6000,"startOfParagraph":false},{"content":"That's more of a conceptual thing to understand.","startTime":2410000,"duration":4000,"startOfParagraph":false},{"content":"I would take a look at the threads short","startTime":2414000,"duration":3000,"startOfParagraph":false},{"content":"if you'd like to learn more about that.","startTime":2417000,"duration":4000,"startOfParagraph":false},{"content":"Let's see, I believe there might have been ","startTime":2421000,"duration":5000,"startOfParagraph":true},{"content":"a problem on this in one of these.","startTime":2426000,"duration":5000,"startOfParagraph":false},{"content":"Again, I think threads and events are not something that we will cover in C","startTime":2431000,"duration":4000,"startOfParagraph":false},{"content":"just because it's significantly more difficult than in Scratch.","startTime":2435000,"duration":6000,"startOfParagraph":false},{"content":"You shouldn't worry about it there, but definitely understand the concepts,","startTime":2441000,"duration":3000,"startOfParagraph":false},{"content":"understand what's going on.","startTime":2444000,"duration":3000,"startOfParagraph":false},{"content":"Before we move on, any questions on Week 0 material?","startTime":2447000,"duration":5000,"startOfParagraph":false},{"content":"Everybody feeling pretty good?","startTime":2452000,"duration":3000,"startOfParagraph":false},{"content":"Understanding variables and what a variable is?","startTime":2455000,"duration":8000,"startOfParagraph":false},{"content":"Moving on. Week 1.","startTime":2463000,"duration":5000,"startOfParagraph":true},{"content":"A couple of things here that weren't particularly covered","startTime":2468000,"duration":4000,"startOfParagraph":false},{"content":"in the quiz review necessarily and also are more conceptual things to think about.","startTime":2472000,"duration":9000,"startOfParagraph":false},{"content":"The first is this notion of what source code, compilers and object code are.","startTime":2481000,"duration":9000,"startOfParagraph":false},{"content":"Anybody? Basil.","startTime":2490000,"duration":2000,"startOfParagraph":false},{"content":"Is object code—I mean source code is what you put into clang,","startTime":2492000,"duration":5000,"startOfParagraph":false},{"content":"and object code is what clang puts out so that your computer can read the program.","startTime":2497000,"duration":5000,"startOfParagraph":false},{"content":"Exactly.","startTime":2502000,"duration":2000,"startOfParagraph":false},{"content":"Source code is the C code that you actually type up.","startTime":2504000,"duration":3000,"startOfParagraph":false},{"content":"Object code is what you get out of clang. ","startTime":2507000,"duration":3000,"startOfParagraph":false},{"content":"It's the 0s and 1s in that binary format.","startTime":2510000,"duration":4000,"startOfParagraph":false},{"content":"Then what happens is when you have a bunch of object files,","startTime":2514000,"duration":5000,"startOfParagraph":false},{"content":"say you're compiling a project or a program that uses multiple source code files,","startTime":2519000,"duration":5000,"startOfParagraph":false},{"content":"which by convention are given the .c file extension.","startTime":2524000,"duration":5000,"startOfParagraph":false},{"content":"That's why we have caesar.c, vigenère.c.","startTime":2529000,"duration":4000,"startOfParagraph":false},{"content":"If you're writing Java programs you give them the extension .java.","startTime":2533000,"duration":5000,"startOfParagraph":false},{"content":"Python programs have the extension .py often.","startTime":2538000,"duration":6000,"startOfParagraph":false},{"content":"Once you have multiple .c files, you compile them.","startTime":2544000,"duration":2000,"startOfParagraph":true},{"content":"Clang spits out all this binary junk.","startTime":2546000,"duration":3000,"startOfParagraph":false},{"content":"Then because you only want 1 program","startTime":2549000,"duration":4000,"startOfParagraph":false},{"content":"you have the linker link all of these object files together","startTime":2553000,"duration":4000,"startOfParagraph":false},{"content":"into 1 executable file.","startTime":2557000,"duration":3000,"startOfParagraph":false},{"content":"This is also what happens when you use the CS50 library, for example.","startTime":2560000,"duration":5000,"startOfParagraph":false},{"content":"The CS50 library is both that .h header file","startTime":2565000,"duration":5000,"startOfParagraph":false},{"content":"that you read, that #includecs50.h.","startTime":2570000,"duration":3000,"startOfParagraph":false},{"content":"And then it's also a special binary library file","startTime":2573000,"duration":5000,"startOfParagraph":false},{"content":"that's been compiled that is 0s and 1s,","startTime":2578000,"duration":4000,"startOfParagraph":false},{"content":"and that -l flag, so if we go back to our Spaces and we look really quickly","startTime":2582000,"duration":6000,"startOfParagraph":false},{"content":"at what's going on here when we look at our clang command,","startTime":2588000,"duration":3000,"startOfParagraph":false},{"content":"what we've got is this is our source code file right here.","startTime":2591000,"duration":4000,"startOfParagraph":false},{"content":"These are a bunch of compiler flags.","startTime":2595000,"duration":3000,"startOfParagraph":false},{"content":"And then at the very end, these -l flags link in","startTime":2598000,"duration":4000,"startOfParagraph":false},{"content":"the actual binary files for these 2 libraries, the CS50 library and then the math library.","startTime":2602000,"duration":8000,"startOfParagraph":false},{"content":"Understanding each type of files' purpose ","startTime":2610000,"duration":5000,"startOfParagraph":true},{"content":"in the compilation process is something you'll want to be able to","startTime":2615000,"duration":3000,"startOfParagraph":false},{"content":"give at least a high level overview of.","startTime":2618000,"duration":5000,"startOfParagraph":false},{"content":"Source code comes in. Object code comes out.","startTime":2623000,"duration":3000,"startOfParagraph":false},{"content":"Object code files link together, and you get a beautiful, executable file.","startTime":2626000,"duration":7000,"startOfParagraph":false},{"content":"Cool.","startTime":2633000,"duration":2000,"startOfParagraph":false},{"content":"This is also where you can get errors at multiple points","startTime":2635000,"duration":3000,"startOfParagraph":false},{"content":"in the compilation process.","startTime":2638000,"duration":2000,"startOfParagraph":false},{"content":"This is where, for example, if you take out this linking flag,","startTime":2640000,"duration":4000,"startOfParagraph":false},{"content":"the CS50 flag, and you omit it in Spaces or when you're running your code,","startTime":2644000,"duration":6000,"startOfParagraph":false},{"content":"this is where you'll get an error in the linking phase,","startTime":2650000,"duration":3000,"startOfParagraph":false},{"content":"and the linker will say, \"Hey, you called a function GetString","startTime":2653000,"duration":5000,"startOfParagraph":false},{"content":"that's in the CS50 library.\"","startTime":2658000,"duration":2000,"startOfParagraph":false},{"content":"\"You told me it was in the CS50 library, and I can't find the code for it.\"","startTime":2660000,"duration":5000,"startOfParagraph":false},{"content":"That's where you have to link it in, and that's separate","startTime":2665000,"duration":3000,"startOfParagraph":false},{"content":"from a compiler error because the compiler is looking at syntax and that kind of stuff.","startTime":2668000,"duration":5000,"startOfParagraph":false},{"content":"It's good to know what's going on when.","startTime":2673000,"duration":5000,"startOfParagraph":false},{"content":"Other things to know about.","startTime":2678000,"duration":4000,"startOfParagraph":true},{"content":"I would say you definitely want to take a look at the short on typecasting done by Jordan","startTime":2682000,"duration":7000,"startOfParagraph":false},{"content":"to understand what ints are under the hood,","startTime":2689000,"duration":6000,"startOfParagraph":false},{"content":"what chars are under the hood.","startTime":2695000,"duration":3000,"startOfParagraph":false},{"content":"When we talk about ASCII and we actually look at the ASCII table,","startTime":2698000,"duration":4000,"startOfParagraph":false},{"content":"what that's doing is giving us an under the hood look","startTime":2702000,"duration":5000,"startOfParagraph":false},{"content":"at how the computer actually represents capital A and the digit 7","startTime":2707000,"duration":6000,"startOfParagraph":false},{"content":"and a comma and a question mark.","startTime":2713000,"duration":4000,"startOfParagraph":false},{"content":"The computer also has special ways to represent","startTime":2717000,"duration":3000,"startOfParagraph":false},{"content":"the number 7 as an integer.","startTime":2720000,"duration":3000,"startOfParagraph":false},{"content":"It has a special way to represent the number 7 as a floating point number,","startTime":2723000,"duration":4000,"startOfParagraph":false},{"content":"and those are very different.","startTime":2727000,"duration":2000,"startOfParagraph":false},{"content":"Typecasting is how you tell the computer \"Hey, I want you to convert ","startTime":2729000,"duration":3000,"startOfParagraph":false},{"content":"from one representation to another representation.\"","startTime":2732000,"duration":5000,"startOfParagraph":false},{"content":"Why don't we take a look at that.","startTime":2737000,"duration":3000,"startOfParagraph":false},{"content":"I would also take a look at the short on libraries and the short on compilers.","startTime":2740000,"duration":4000,"startOfParagraph":true},{"content":"Those talk about the process of compilation,","startTime":2744000,"duration":3000,"startOfParagraph":false},{"content":"what a library is, and go over some of these questions that you might get asked.","startTime":2747000,"duration":6000,"startOfParagraph":false},{"content":"Questions on Week 1 material?","startTime":2753000,"duration":2000,"startOfParagraph":false},{"content":"Are there any topics in here that seem daunting you'd like to cover?","startTime":2755000,"duration":8000,"startOfParagraph":false},{"content":"I'm trying to blow through most of these earlier topics so that we can get to","startTime":2763000,"duration":4000,"startOfParagraph":false},{"content":"pointers and do a little bit of recursion.","startTime":2767000,"duration":6000,"startOfParagraph":false},{"content":"Thoughts?","startTime":2773000,"duration":2000,"startOfParagraph":false},{"content":"Anything to cover?","startTime":2775000,"duration":4000,"startOfParagraph":false},{"content":"Time for some chocolate maybe?","startTime":2779000,"duration":2000,"startOfParagraph":false},{"content":"You guys are working through it.","startTime":2781000,"duration":2000,"startOfParagraph":false},{"content":"I'm going to keep sipping on my coffee.","startTime":2783000,"duration":3000,"startOfParagraph":false},{"content":"Week 2.","startTime":2786000,"duration":5000,"startOfParagraph":false},{"content":"Good call, good call.","startTime":2791000,"duration":3000,"startOfParagraph":false},{"content":"In Week 2 we talked a little bit more about functions.","startTime":2794000,"duration":4000,"startOfParagraph":false},{"content":"In the first few problem sets we didn't really write any functions at all","startTime":2798000,"duration":5000,"startOfParagraph":true},{"content":"other than which function?","startTime":2803000,"duration":2000,"startOfParagraph":false},{"content":"[Student] Main.>>Main, exactly.","startTime":2805000,"duration":2000,"startOfParagraph":false},{"content":"And so we've seen the different costumes that main wears.","startTime":2807000,"duration":4000,"startOfParagraph":false},{"content":"There's the one in which it takes no arguments,","startTime":2811000,"duration":3000,"startOfParagraph":false},{"content":"and we just say void in between the parentheses,","startTime":2814000,"duration":4000,"startOfParagraph":false},{"content":"and then there's the other one where we do want to take command line arguments,","startTime":2818000,"duration":3000,"startOfParagraph":false},{"content":"and as we saw, that's where you have int argc and string argv array","startTime":2821000,"duration":7000,"startOfParagraph":false},{"content":"or now that we've actually exposed string to be the char* that it is","startTime":2828000,"duration":5000,"startOfParagraph":false},{"content":"we're going to start writing it as char* argv and then brackets.","startTime":2833000,"duration":7000,"startOfParagraph":false},{"content":"In Problem Set 3, you guys saw a bunch of functions,","startTime":2840000,"duration":2000,"startOfParagraph":false},{"content":"and you implemented a bunch of functions, draw, look up, scramble.","startTime":2842000,"duration":5000,"startOfParagraph":false},{"content":"The prototypes were all written there for you.","startTime":2847000,"duration":4000,"startOfParagraph":false},{"content":"What I wanted to talk about here with functions really quickly ","startTime":2851000,"duration":2000,"startOfParagraph":true},{"content":"is that there are 3 parts to them whenever you write a function.","startTime":2853000,"duration":5000,"startOfParagraph":false},{"content":"You have to specify the return type of the function.","startTime":2858000,"duration":5000,"startOfParagraph":false},{"content":"You have to specify a name for the function, and then you have to specify ","startTime":2863000,"duration":3000,"startOfParagraph":false},{"content":"the argument list or the parameter list.","startTime":2866000,"duration":5000,"startOfParagraph":false},{"content":"For example, if I were to write a function to sum up a bunch of integers","startTime":2871000,"duration":6000,"startOfParagraph":false},{"content":"and then return to me the sum what would be my return type","startTime":2877000,"duration":6000,"startOfParagraph":false},{"content":"if I wanted to sum integers and then return the sum?","startTime":2883000,"duration":3000,"startOfParagraph":false},{"content":"Then the name of the function.","startTime":2886000,"duration":6000,"startOfParagraph":false},{"content":"If I go ahead and write in green, this part is the return type.","startTime":2892000,"duration":15000,"startOfParagraph":false},{"content":"This part is the name.","startTime":2907000,"duration":7000,"startOfParagraph":false},{"content":"And then in between parentheses ","startTime":2914000,"duration":6000,"startOfParagraph":false},{"content":"is where I give the arguments,","startTime":2920000,"duration":6000,"startOfParagraph":false},{"content":"often abbreviated as args, sometimes called params for parameters.","startTime":2926000,"duration":10000,"startOfParagraph":false},{"content":"And if you have one, you just specify the one.","startTime":2936000,"duration":4000,"startOfParagraph":false},{"content":"If you have multiple you separate each one with a comma.","startTime":2940000,"duration":6000,"startOfParagraph":false},{"content":"And for each argument you give it 2 things which are—Kevin?","startTime":2946000,"duration":7000,"startOfParagraph":false},{"content":"[Kevin] You have to give the type and then the name.","startTime":2953000,"duration":5000,"startOfParagraph":false},{"content":"And then the name, and the name is the name that you're going to use","startTime":2958000,"duration":3000,"startOfParagraph":false},{"content":"to refer to that argument within the sum function,","startTime":2961000,"duration":4000,"startOfParagraph":false},{"content":"within the function that you're currently writing.","startTime":2965000,"duration":2000,"startOfParagraph":false},{"content":"You don't have to—for example, if I'm going to sum up,","startTime":2967000,"duration":5000,"startOfParagraph":true},{"content":"say, an array of integers—we'll do int array,","startTime":2972000,"duration":9000,"startOfParagraph":false},{"content":"and I'll give myself some curly braces there—","startTime":2981000,"duration":5000,"startOfParagraph":false},{"content":"then when I pass an array to the sum function ","startTime":2986000,"duration":5000,"startOfParagraph":false},{"content":"I pass it in the first position of the argument list.","startTime":2991000,"duration":4000,"startOfParagraph":false},{"content":"But the array that I pass in doesn't have to have the name arr.","startTime":2995000,"duration":4000,"startOfParagraph":false},{"content":"Arr is going to be how I refer to that argument within the body of the function.","startTime":2999000,"duration":8000,"startOfParagraph":false},{"content":"The other thing that we need to take into account, ","startTime":3007000,"duration":3000,"startOfParagraph":false},{"content":"and this is slightly different from functions, but I think it's an important point,","startTime":3010000,"duration":4000,"startOfParagraph":false},{"content":"is that in C when I'm writing a function like this","startTime":3014000,"duration":6000,"startOfParagraph":false},{"content":"how do I know how many elements are in this array?","startTime":3020000,"duration":9000,"startOfParagraph":false},{"content":"This is somewhat of a trick question.","startTime":3029000,"duration":2000,"startOfParagraph":false},{"content":"We talked about this a little bit in last week's section.","startTime":3031000,"duration":4000,"startOfParagraph":false},{"content":"How do I know the number of elements inside an array in C?","startTime":3035000,"duration":5000,"startOfParagraph":false},{"content":"Is there a way?","startTime":3040000,"duration":4000,"startOfParagraph":false},{"content":"It turns out that there's no way to know.","startTime":3044000,"duration":5000,"startOfParagraph":true},{"content":"You have to pass it in separately.","startTime":3049000,"duration":3000,"startOfParagraph":false},{"content":"There is a trick that you can do","startTime":3052000,"duration":3000,"startOfParagraph":false},{"content":"if you're in the same function in which the array has been declared,","startTime":3055000,"duration":5000,"startOfParagraph":false},{"content":"and you're working with a stack array.","startTime":3060000,"duration":4000,"startOfParagraph":false},{"content":"But that only works if you're in the same function.","startTime":3064000,"duration":2000,"startOfParagraph":false},{"content":"Once you pass an array to another function or if you've declared an array","startTime":3066000,"duration":3000,"startOfParagraph":false},{"content":"and you put that array on the heap, you've used malloc","startTime":3069000,"duration":3000,"startOfParagraph":false},{"content":" and that kind of stuff, then all bets are off. ","startTime":3072000,"duration":3000,"startOfParagraph":false},{"content":"Then you actually have to pass around","startTime":3075000,"duration":3000,"startOfParagraph":false},{"content":"a special argument or another parameter","startTime":3078000,"duration":3000,"startOfParagraph":false},{"content":"telling you how big the array is.","startTime":3081000,"duration":2000,"startOfParagraph":false},{"content":"In this case, I'd want to use a comma—I'm sorry, it's going off the screen here—","startTime":3083000,"duration":5000,"startOfParagraph":false},{"content":"and I'd pass in another argument","startTime":3088000,"duration":4000,"startOfParagraph":false},{"content":" and call it int len for the length.","startTime":3092000,"duration":8000,"startOfParagraph":false},{"content":"One thing that might come up on the quiz","startTime":3100000,"duration":4000,"startOfParagraph":true},{"content":"is asking you to write or implement a particular function called something.","startTime":3104000,"duration":5000,"startOfParagraph":false},{"content":"If we don't give you the prototype, so this whole thing here,","startTime":3109000,"duration":5000,"startOfParagraph":false},{"content":"this whole mess is called the function declaration or the function prototype,","startTime":3114000,"duration":4000,"startOfParagraph":false},{"content":"this is one of the first things that you'll want to nail down if it's not given ","startTime":3118000,"duration":3000,"startOfParagraph":false},{"content":"to you right away on the quiz.","startTime":3121000,"duration":2000,"startOfParagraph":false},{"content":"The other trick I've learned is that","startTime":3123000,"duration":3000,"startOfParagraph":false},{"content":"say we do give you a prototype for a function, and we say, \"Hey, you've got to write it.\"","startTime":3126000,"duration":5000,"startOfParagraph":false},{"content":"Inside the curly braces that you have on the quiz","startTime":3131000,"duration":5000,"startOfParagraph":false},{"content":"if you notice that there is a return type and you notice that the return type","startTime":3136000,"duration":4000,"startOfParagraph":false},{"content":"is something other than void, which means that the function doesn't return anything,","startTime":3140000,"duration":5000,"startOfParagraph":false},{"content":"then one thing you definitely want to do is write","startTime":3145000,"duration":3000,"startOfParagraph":false},{"content":"some sort of return statement at the very end of the function.","startTime":3148000,"duration":5000,"startOfParagraph":false},{"content":"Return, and in this case, we'll put a blank because we want to fill in the blank.","startTime":3153000,"duration":7000,"startOfParagraph":false},{"content":"But this gets you thinking in the right way about how am I going to approach this problem?","startTime":3160000,"duration":4000,"startOfParagraph":false},{"content":"And it reminds you you're going to have to return a value","startTime":3164000,"duration":5000,"startOfParagraph":false},{"content":"to the caller of the function.","startTime":3169000,"duration":2000,"startOfParagraph":false},{"content":"Yeah.>>[Student] Does style apply when we're writing code on the quiz?","startTime":3171000,"duration":3000,"startOfParagraph":true},{"content":"Such as indentation and that kind of stuff?>>[Student] Yeah.","startTime":3174000,"duration":4000,"startOfParagraph":false},{"content":"No, not as much.","startTime":3178000,"duration":2000,"startOfParagraph":false},{"content":"I think a lot of—this is something we'll clarify on the quiz on the day of,","startTime":3180000,"duration":9000,"startOfParagraph":false},{"content":"but typically worrying about #includes and that kind of stuff, it's kind of outside.","startTime":3189000,"duration":6000,"startOfParagraph":false},{"content":"[Student] Do you need to comment your handwritten code?","startTime":3195000,"duration":2000,"startOfParagraph":false},{"content":"Do you need to comment your handwritten code?","startTime":3197000,"duration":2000,"startOfParagraph":false},{"content":"Commenting is always good if you're worried about partial credit","startTime":3199000,"duration":5000,"startOfParagraph":false},{"content":"or you want to communicate your intent to the grader.","startTime":3204000,"duration":5000,"startOfParagraph":false},{"content":"But I, again, will clarify on the quiz itself and on the quiz day,","startTime":3209000,"duration":4000,"startOfParagraph":false},{"content":"but I don't believe that you'll be required to write comments, no.","startTime":3213000,"duration":6000,"startOfParagraph":false},{"content":"Typically not, but it's definitely the sort of thing where ","startTime":3219000,"duration":3000,"startOfParagraph":false},{"content":"you can communicate your intent, like \"Hey, this is where I'm going with it.\"","startTime":3222000,"duration":3000,"startOfParagraph":false},{"content":"And sometimes that can help with partial credit.","startTime":3225000,"duration":4000,"startOfParagraph":false},{"content":"Cool.","startTime":3229000,"duration":2000,"startOfParagraph":false},{"content":"Basil.","startTime":3231000,"duration":2000,"startOfParagraph":true},{"content":"[Basil] What's the difference between declaring, say, int lang","startTime":3233000,"duration":3000,"startOfParagraph":false},{"content":"in the arguments or parameters versus declaring a variable within the function?","startTime":3236000,"duration":7000,"startOfParagraph":false},{"content":"Wow, coffee went down the windpipe.","startTime":3243000,"duration":2000,"startOfParagraph":false},{"content":"[Basil] Like which things we want to put in arguments.","startTime":3245000,"duration":2000,"startOfParagraph":false},{"content":"Yeah, that's a great question.","startTime":3247000,"duration":2000,"startOfParagraph":false},{"content":"How do you choose what things you want to put in the arguments","startTime":3249000,"duration":2000,"startOfParagraph":false},{"content":"versus what things you should do inside of the function?","startTime":3251000,"duration":6000,"startOfParagraph":false},{"content":"In this case we included both of these as arguments","startTime":3257000,"duration":7000,"startOfParagraph":false},{"content":"because they're something that whoever is going to use the sum function","startTime":3264000,"duration":5000,"startOfParagraph":false},{"content":"needs to specify those things.","startTime":3269000,"duration":3000,"startOfParagraph":false},{"content":"The sum function, like we talked about, has no way of knowing","startTime":3272000,"duration":3000,"startOfParagraph":true},{"content":"how big the array is it gets from its caller or whoever is using the sum function.","startTime":3275000,"duration":5000,"startOfParagraph":false},{"content":"It has no way of knowing how big that array is.","startTime":3280000,"duration":4000,"startOfParagraph":false},{"content":"The reason we pass in this length right here as an argument","startTime":3284000,"duration":4000,"startOfParagraph":false},{"content":"is because that's something that we're basically telling the caller of the function,","startTime":3288000,"duration":3000,"startOfParagraph":false},{"content":"whoever is going to use the sum function, \"Hey, not only do you have to give us an array","startTime":3291000,"duration":4000,"startOfParagraph":false},{"content":"of ints, you also have to tell us how big the array that you've given us is.\"","startTime":3295000,"duration":4000,"startOfParagraph":false},{"content":"[Basil] Those will both be command line arguments?","startTime":3299000,"duration":4000,"startOfParagraph":false},{"content":"No, these are actual arguments that you would pass to the function.","startTime":3303000,"duration":3000,"startOfParagraph":false},{"content":"Let me do a new page here.","startTime":3306000,"duration":4000,"startOfParagraph":true},{"content":"[Basil] Like name would pass—","startTime":3310000,"duration":3000,"startOfParagraph":false},{"content":"[Nate H.] If I have int main (void), ","startTime":3313000,"duration":11000,"startOfParagraph":false},{"content":"and I'm going to put in my return 0 down here at the bottom,","startTime":3324000,"duration":3000,"startOfParagraph":false},{"content":"and say I want to call the sum function.","startTime":3327000,"duration":4000,"startOfParagraph":false},{"content":"I want to say int x = sum( );","startTime":3331000,"duration":11000,"startOfParagraph":false},{"content":"To use the sum function I have to pass in both the array that I want to sum up","startTime":3342000,"duration":4000,"startOfParagraph":false},{"content":"and the length of the array, so this is where","startTime":3346000,"duration":5000,"startOfParagraph":false},{"content":"assuming I had an array of ints,","startTime":3351000,"duration":3000,"startOfParagraph":false},{"content":"say I had int numbaz [ ] = 1, 2, 3, ","startTime":3354000,"duration":18000,"startOfParagraph":false},{"content":"kind of use that hacked up syntax right there,","startTime":3372000,"duration":4000,"startOfParagraph":false},{"content":"then what I would do is in sum I would want to pass in","startTime":3376000,"duration":5000,"startOfParagraph":false},{"content":"both numbaz and the number 3","startTime":3381000,"duration":6000,"startOfParagraph":false},{"content":"to tell the sum function \"Okay, here's the array I want you to sum.\"","startTime":3387000,"duration":3000,"startOfParagraph":false},{"content":"\"Here's its size.\"","startTime":3390000,"duration":4000,"startOfParagraph":false},{"content":"Does that make sense? Does that answer your question?","startTime":3394000,"duration":5000,"startOfParagraph":false},{"content":"In many ways it does parallel what we're doing with main","startTime":3399000,"duration":3000,"startOfParagraph":true},{"content":"when we have the command line arguments.","startTime":3402000,"duration":2000,"startOfParagraph":false},{"content":"A program like Caesar cipher, for example, that needed","startTime":3404000,"duration":3000,"startOfParagraph":false},{"content":"command line arguments would not be able to do anything.","startTime":3407000,"duration":6000,"startOfParagraph":false},{"content":"It wouldn't know how to encrypt if you didn't tell it what key to use","startTime":3413000,"duration":4000,"startOfParagraph":false},{"content":"or if you didn't tell it what string you wanted to encrypt.","startTime":3417000,"duration":6000,"startOfParagraph":false},{"content":"Prompting for input, this is where we've got 2 different mechanisms","startTime":3423000,"duration":5000,"startOfParagraph":false},{"content":"for taking input in from the user, for taking information in from the user.","startTime":3428000,"duration":6000,"startOfParagraph":false},{"content":"For Problem Set 1 we saw this GetInt, GetString, GetFloat way","startTime":3434000,"duration":5000,"startOfParagraph":false},{"content":"of prompting for input, and that's called using the standard input stream.","startTime":3439000,"duration":7000,"startOfParagraph":false},{"content":"It's slightly different.","startTime":3446000,"duration":2000,"startOfParagraph":false},{"content":"It's something that you can do at one time as opposed to","startTime":3448000,"duration":3000,"startOfParagraph":false},{"content":"when you invoke the program, when you start the program running.","startTime":3451000,"duration":4000,"startOfParagraph":false},{"content":"The command line arguments all are specified when you start the program running.","startTime":3455000,"duration":6000,"startOfParagraph":false},{"content":"We've been mixing the two of those.","startTime":3461000,"duration":6000,"startOfParagraph":false},{"content":"When we use arguments to a function, it's much like command line arguments to main.","startTime":3467000,"duration":5000,"startOfParagraph":false},{"content":"It's when you invoke the function you need to tell it","startTime":3472000,"duration":4000,"startOfParagraph":false},{"content":"what exactly it needs in order to perform its tasks.","startTime":3476000,"duration":9000,"startOfParagraph":false},{"content":"Another good thing to look at—and I'll let you look at it in your spare time,","startTime":3485000,"duration":3000,"startOfParagraph":false},{"content":"and it was covered in the quiz—was this notion of scope ","startTime":3488000,"duration":3000,"startOfParagraph":false},{"content":"and local variables versus global variables.","startTime":3491000,"duration":4000,"startOfParagraph":false},{"content":"Do pay attention to that.","startTime":3495000,"duration":3000,"startOfParagraph":false},{"content":"Now that we're getting on to this other stuff,","startTime":3498000,"duration":5000,"startOfParagraph":true},{"content":"in Week 3 we started talking about searching and sorting.","startTime":3503000,"duration":4000,"startOfParagraph":false},{"content":"Searching and sorting, at least in CS50,","startTime":3507000,"duration":5000,"startOfParagraph":false},{"content":"is very much an introduction to some of the more theoretical parts of computer science.","startTime":3512000,"duration":7000,"startOfParagraph":false},{"content":"The problem of searching, the problem of sorting","startTime":3519000,"duration":3000,"startOfParagraph":false},{"content":"are big, canonical problems.","startTime":3522000,"duration":4000,"startOfParagraph":false},{"content":"How do you find a particular number in an array of billions of integers?","startTime":3526000,"duration":6000,"startOfParagraph":false},{"content":"How do you find a particular name inside a phone book","startTime":3532000,"duration":3000,"startOfParagraph":false},{"content":"that's stored on your laptop?","startTime":3535000,"duration":4000,"startOfParagraph":false},{"content":"And so we introduce this notion of asymptotic run times","startTime":3539000,"duration":5000,"startOfParagraph":false},{"content":"to really quantify how long, how hard these problem are,","startTime":3544000,"duration":7000,"startOfParagraph":false},{"content":"how long they take to solve.","startTime":3551000,"duration":3000,"startOfParagraph":false},{"content":"In, I believe, 2011's quiz there's a problem that I think merits","startTime":3554000,"duration":6000,"startOfParagraph":false},{"content":"covering very quickly, which is this one, problem 12.","startTime":3560000,"duration":7000,"startOfParagraph":false},{"content":"O no, it's Omega.","startTime":3567000,"duration":5000,"startOfParagraph":false},{"content":"Here we're talking about the fastest possible run time","startTime":3572000,"duration":9000,"startOfParagraph":true},{"content":"for a particular algorithm and then the slowest possible run time.","startTime":3581000,"duration":5000,"startOfParagraph":false},{"content":"This Omega and O are really just shortcuts.","startTime":3586000,"duration":6000,"startOfParagraph":false},{"content":"They're notational shortcuts for saying","startTime":3592000,"duration":3000,"startOfParagraph":false},{"content":"how fast in the best possible case will our algorithm run,","startTime":3595000,"duration":4000,"startOfParagraph":false},{"content":"and how slow in the worst possible case will our algorithm run?","startTime":3599000,"duration":7000,"startOfParagraph":false},{"content":"Let's do a couple of these, and these were also covered","startTime":3606000,"duration":4000,"startOfParagraph":false},{"content":"in the short on asymptotic notation, which I highly recommend.","startTime":3610000,"duration":3000,"startOfParagraph":false},{"content":"Jackson did a really good job.","startTime":3613000,"duration":4000,"startOfParagraph":false},{"content":"With binary search, we talk about binary search as being an algorithm, ","startTime":3617000,"duration":6000,"startOfParagraph":false},{"content":"and we usually talk about it in terms of its big O.","startTime":3623000,"duration":5000,"startOfParagraph":false},{"content":"What is the big O?","startTime":3628000,"duration":2000,"startOfParagraph":false},{"content":"What is the slowest possible run time of binary search?","startTime":3630000,"duration":4000,"startOfParagraph":false},{"content":"[Student] N²?","startTime":3634000,"duration":2000,"startOfParagraph":false},{"content":"Close, I guess similar to that.","startTime":3636000,"duration":5000,"startOfParagraph":false},{"content":"It's a lot faster than that.","startTime":3641000,"duration":2000,"startOfParagraph":false},{"content":"[Student] Binary?>>Yeah, binary search.","startTime":3643000,"duration":2000,"startOfParagraph":false},{"content":"[Student] It's log n.","startTime":3645000,"duration":2000,"startOfParagraph":false},{"content":"Log n, so what does log n mean?","startTime":3647000,"duration":2000,"startOfParagraph":false},{"content":"It halves it each iteration.","startTime":3649000,"duration":2000,"startOfParagraph":false},{"content":"Exactly, so in the slowest possible case,","startTime":3651000,"duration":5000,"startOfParagraph":false},{"content":"say if you have a sorted array ","startTime":3656000,"duration":4000,"startOfParagraph":false},{"content":"of a million integers and the number you're looking for","startTime":3660000,"duration":8000,"startOfParagraph":false},{"content":"is either the very first element in the array or the very last element in the array.","startTime":3668000,"duration":6000,"startOfParagraph":false},{"content":"Remember, the binary search algorithm works by looking at the middle element,","startTime":3674000,"duration":4000,"startOfParagraph":false},{"content":"seeing if that's the match that you're looking for.","startTime":3678000,"duration":3000,"startOfParagraph":false},{"content":"If it is, then great, you found it.","startTime":3681000,"duration":2000,"startOfParagraph":false},{"content":"In the best possible case, how fast does binary search run?","startTime":3683000,"duration":4000,"startOfParagraph":true},{"content":"[Students] 1.","startTime":3687000,"duration":2000,"startOfParagraph":false},{"content":"1, it's constant time, big O of 1. Yeah.","startTime":3689000,"duration":3000,"startOfParagraph":false},{"content":"[Student] I have a question. When you say log of n, you mean with respect to base 2, right?","startTime":3692000,"duration":4000,"startOfParagraph":false},{"content":"Yes, so that's the other thing.","startTime":3696000,"duration":4000,"startOfParagraph":false},{"content":"We say log n, and I guess when I was in high school","startTime":3700000,"duration":4000,"startOfParagraph":false},{"content":"I always assumed that log was base 10.","startTime":3704000,"duration":4000,"startOfParagraph":false},{"content":"Yeah, so yes, log base 2 typically is what we use.","startTime":3708000,"duration":9000,"startOfParagraph":false},{"content":"Again, going back to binary search, if you're searching for either","startTime":3717000,"duration":5000,"startOfParagraph":false},{"content":"the element at the very end or the element at the very beginning,","startTime":3722000,"duration":3000,"startOfParagraph":false},{"content":"because you start in the middle and then you discard","startTime":3725000,"duration":3000,"startOfParagraph":false},{"content":"whichever half doesn't meet the criteria that you're looking for,","startTime":3728000,"duration":5000,"startOfParagraph":false},{"content":"and you go to the next half and the next half and the next half.","startTime":3733000,"duration":2000,"startOfParagraph":false},{"content":"If I'm searching for the largest element in the million integer array","startTime":3735000,"duration":4000,"startOfParagraph":false},{"content":"I'm going to halve it at most log of 1 million times","startTime":3739000,"duration":6000,"startOfParagraph":false},{"content":"before I finally test and see that the element I'm looking for ","startTime":3745000,"duration":3000,"startOfParagraph":false},{"content":"is in the biggest or in the highest index of the array,","startTime":3748000,"duration":5000,"startOfParagraph":false},{"content":"and that will take log of n, log of 1 million times.","startTime":3753000,"duration":5000,"startOfParagraph":false},{"content":"Bubble sort.","startTime":3758000,"duration":2000,"startOfParagraph":true},{"content":"Do you guys remember the bubble sort algorithm?","startTime":3760000,"duration":3000,"startOfParagraph":false},{"content":"Kevin, can you give me a quick recap of what happened in the bubble sort algorithm?","startTime":3763000,"duration":4000,"startOfParagraph":false},{"content":"[Kevin] Basically it goes through everything in the list.","startTime":3767000,"duration":3000,"startOfParagraph":false},{"content":"It looks at the first two. ","startTime":3770000,"duration":2000,"startOfParagraph":false},{"content":"If the first one is bigger than the second one it swaps them.","startTime":3772000,"duration":3000,"startOfParagraph":false},{"content":"Then it compares second and third, same thing, swaps, ","startTime":3775000,"duration":3000,"startOfParagraph":false},{"content":"third and fourth, all the way down.","startTime":3778000,"duration":2000,"startOfParagraph":false},{"content":"Bigger numbers will follow up to the end. ","startTime":3780000,"duration":3000,"startOfParagraph":false},{"content":"And after however many loops you're done.","startTime":3783000,"duration":4000,"startOfParagraph":false},{"content":"Exactly, so what Kevin said is that we'll watch bigger numbers","startTime":3787000,"duration":4000,"startOfParagraph":false},{"content":"bubble up to the end of the array.","startTime":3791000,"duration":4000,"startOfParagraph":false},{"content":"For example, do you mind walking us through this example if this is our array?","startTime":3795000,"duration":4000,"startOfParagraph":false},{"content":"[Kevin] You'll take 2 and 3.","startTime":3799000,"duration":2000,"startOfParagraph":false},{"content":"3 is bigger than 2, so you swap them.","startTime":3801000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] Right, so we swap these, and so we get 2, 3, 6, 4, and 9.","startTime":3803000,"duration":6000,"startOfParagraph":false},{"content":"[Kevin] Then you compare the 3 and 6.","startTime":3809000,"duration":2000,"startOfParagraph":false},{"content":"3 is smaller than 6, so you leave them,","startTime":3811000,"duration":2000,"startOfParagraph":false},{"content":"and 6 and 4, you'd swap them because 4 is smaller than 6.","startTime":3813000,"duration":4000,"startOfParagraph":false},{"content":"[Nate H.] Right, so I get 2, 3, 4, 6, 9.","startTime":3817000,"duration":5000,"startOfParagraph":false},{"content":"[Kevin] And 9 is bigger than 6, so you leave it.","startTime":3822000,"duration":4000,"startOfParagraph":false},{"content":"And you'd go back through it again.","startTime":3826000,"duration":2000,"startOfParagraph":false},{"content":"[Nate H.] Am I done at this point?>>[Kevin] No.","startTime":3828000,"duration":2000,"startOfParagraph":true},{"content":"And why am I not done at this point?","startTime":3830000,"duration":2000,"startOfParagraph":false},{"content":"Because it looks like my array is sorted. I'm looking at it.","startTime":3832000,"duration":2000,"startOfParagraph":false},{"content":"[Kevin] Go through it again and make sure that there are no more swaps","startTime":3834000,"duration":3000,"startOfParagraph":false},{"content":"before you can fully stop.","startTime":3837000,"duration":3000,"startOfParagraph":false},{"content":"Exactly, so you need to keep going through and make sure that there are no swaps","startTime":3840000,"duration":4000,"startOfParagraph":false},{"content":"that you can make at this point.","startTime":3844000,"duration":2000,"startOfParagraph":false},{"content":"It was really just lucky, like you said, that we ended up","startTime":3846000,"duration":2000,"startOfParagraph":false},{"content":"only having to make 1 pass through and we're sorted.","startTime":3848000,"duration":4000,"startOfParagraph":false},{"content":"But to do this in the general case we'll actually have to do this over and over again.","startTime":3852000,"duration":4000,"startOfParagraph":false},{"content":"And in fact, this was an example of the best possible case,","startTime":3856000,"duration":4000,"startOfParagraph":false},{"content":"like we saw in the problem.","startTime":3860000,"duration":4000,"startOfParagraph":false},{"content":"We saw that the best possible case was n.","startTime":3864000,"duration":4000,"startOfParagraph":false},{"content":"We went through the array 1 time.","startTime":3868000,"duration":4000,"startOfParagraph":false},{"content":"What is the worst possible case for this algorithm?","startTime":3872000,"duration":3000,"startOfParagraph":false},{"content":"[Kevin] N².","startTime":3875000,"duration":2000,"startOfParagraph":false},{"content":"And what does that look like? What would an array look like that would take n² time?","startTime":3877000,"duration":4000,"startOfParagraph":false},{"content":"[Kevin] [inaudible] sorted.","startTime":3881000,"duration":2000,"startOfParagraph":false},{"content":"Exactly, so if I had the array 9, 7, 6, 5, 2,","startTime":3883000,"duration":8000,"startOfParagraph":false},{"content":"first the 9 would bubble all the way up.","startTime":3891000,"duration":3000,"startOfParagraph":false},{"content":"After 1 iteration we'd have 7, 6, 5, 2, 9.","startTime":3894000,"duration":5000,"startOfParagraph":false},{"content":"Then the 7 would bubble up, 6, 5, 2, 7, 9, and so on and so forth.","startTime":3899000,"duration":8000,"startOfParagraph":false},{"content":"We'd have to go through the entire array n times,","startTime":3907000,"duration":6000,"startOfParagraph":true},{"content":"and you can actually get slightly more precise than this","startTime":3913000,"duration":3000,"startOfParagraph":false},{"content":"because once we've moved the 9 all the way up into its last possible position","startTime":3916000,"duration":7000,"startOfParagraph":false},{"content":"we know that we never have to compare against that element again.","startTime":3923000,"duration":3000,"startOfParagraph":false},{"content":"Once we start bubbling the 7 up ","startTime":3926000,"duration":3000,"startOfParagraph":false},{"content":"we know that we can stop once the 7 is right before the 9","startTime":3929000,"duration":6000,"startOfParagraph":false},{"content":"since we've already compared the 9 to it.","startTime":3935000,"duration":2000,"startOfParagraph":false},{"content":"If you do this in a smart way it's not truly, I guess, that much time.","startTime":3937000,"duration":9000,"startOfParagraph":false},{"content":"You're not going to compare all the possible [inaudible] combinations","startTime":3946000,"duration":3000,"startOfParagraph":false},{"content":"every single time you go through each iteration.","startTime":3949000,"duration":6000,"startOfParagraph":false},{"content":"But still, when we talk about this upper bound we say that","startTime":3955000,"duration":4000,"startOfParagraph":false},{"content":"you are looking at n² comparisons all the way through.","startTime":3959000,"duration":5000,"startOfParagraph":false},{"content":"Let's go back, and since we're starting to get a little short on time","startTime":3964000,"duration":8000,"startOfParagraph":true},{"content":"I would say you should definitely go through the rest of this table,","startTime":3972000,"duration":3000,"startOfParagraph":false},{"content":"fill it all out.","startTime":3975000,"duration":2000,"startOfParagraph":false},{"content":"Think of examples. Think of concrete examples.","startTime":3977000,"duration":3000,"startOfParagraph":false},{"content":"That's really handy and helpful to do.","startTime":3980000,"duration":2000,"startOfParagraph":false},{"content":"Draw it out.","startTime":3982000,"duration":3000,"startOfParagraph":false},{"content":"This is the sort of table that as you go through in computer science","startTime":3985000,"duration":3000,"startOfParagraph":false},{"content":"you should really start to know these by heart.","startTime":3988000,"duration":4000,"startOfParagraph":false},{"content":"These are the kinds of questions you get in interviews.","startTime":3992000,"duration":2000,"startOfParagraph":false},{"content":"These are sorts of things that are good to know,","startTime":3994000,"duration":2000,"startOfParagraph":false},{"content":"and think about those edge cases, really figuring out how to think about","startTime":3996000,"duration":5000,"startOfParagraph":false},{"content":"knowing that for bubble sort the worst possible array","startTime":4001000,"duration":4000,"startOfParagraph":false},{"content":"to sort with that is one that's in reverse order.","startTime":4005000,"duration":7000,"startOfParagraph":false},{"content":"Pointers. Let's talk a little bit about pointers.","startTime":4012000,"duration":6000,"startOfParagraph":true},{"content":"In the last few minutes we have here","startTime":4018000,"duration":5000,"startOfParagraph":false},{"content":"I know this is something along with file I/O that is rather new.","startTime":4023000,"duration":8000,"startOfParagraph":false},{"content":"When we talk about pointers the reason we want to talk about pointers","startTime":4031000,"duration":8000,"startOfParagraph":false},{"content":"is because, one, when we're working in C","startTime":4039000,"duration":5000,"startOfParagraph":false},{"content":"we are really at a fairly low level compared to most modern programming languages.","startTime":4044000,"duration":9000,"startOfParagraph":false},{"content":"We're actually able to manipulate the variables in memory,","startTime":4053000,"duration":5000,"startOfParagraph":false},{"content":"figure out where they're actually located within our RAM.","startTime":4058000,"duration":5000,"startOfParagraph":false},{"content":"Once you've gone on to take operating system classes you'll see ","startTime":4063000,"duration":3000,"startOfParagraph":false},{"content":"that that's, again, kind of an abstraction.","startTime":4066000,"duration":2000,"startOfParagraph":false},{"content":"That's not actually the case.","startTime":4068000,"duration":2000,"startOfParagraph":false},{"content":"We've got virtual memory that's hiding those details from us.","startTime":4070000,"duration":2000,"startOfParagraph":false},{"content":"But for now you can assume that when you have a program,","startTime":4072000,"duration":6000,"startOfParagraph":true},{"content":"for example, when you start running your Caesar cipher program—","startTime":4078000,"duration":4000,"startOfParagraph":false},{"content":"I'll switch back to my iPad really quickly—","startTime":4082000,"duration":4000,"startOfParagraph":false},{"content":"that at the very beginning your program, if you have, say,","startTime":4086000,"duration":6000,"startOfParagraph":false},{"content":"4 gigabytes of RAM on your laptop,","startTime":4092000,"duration":3000,"startOfParagraph":false},{"content":"you get set aside this chunk, and we'll call this RAM.","startTime":4095000,"duration":6000,"startOfParagraph":false},{"content":"And it starts in a place we're going to call 0,","startTime":4101000,"duration":4000,"startOfParagraph":false},{"content":"and it ends at a place that we'll call 4 gigabytes.","startTime":4105000,"duration":5000,"startOfParagraph":false},{"content":"I really can't write. Man, that is hacked.","startTime":4110000,"duration":7000,"startOfParagraph":false},{"content":"When your program executes","startTime":4117000,"duration":3000,"startOfParagraph":false},{"content":"the operating system carves up RAM,","startTime":4120000,"duration":4000,"startOfParagraph":false},{"content":"and it specifies different segments for different parts of your program to live in.","startTime":4124000,"duration":7000,"startOfParagraph":false},{"content":"Down here this area is kind of a no man's land.","startTime":4131000,"duration":7000,"startOfParagraph":false},{"content":"When you go up a little farther here","startTime":4138000,"duration":4000,"startOfParagraph":false},{"content":"you've got actually the place where","startTime":4142000,"duration":3000,"startOfParagraph":false},{"content":"the code for your program lives.","startTime":4145000,"duration":4000,"startOfParagraph":false},{"content":"That actual binary code, that executable file actually gets loaded into memory","startTime":4149000,"duration":4000,"startOfParagraph":false},{"content":"when you run a program, and it lives in the code segment.","startTime":4153000,"duration":4000,"startOfParagraph":false},{"content":"And as your program executes the processor looks at this code segment","startTime":4157000,"duration":5000,"startOfParagraph":false},{"content":"to figure out what is the next instruction?","startTime":4162000,"duration":2000,"startOfParagraph":false},{"content":"What is the next line of code I need to execute?","startTime":4164000,"duration":3000,"startOfParagraph":false},{"content":"There's also a data segment, and this is where those string constants ","startTime":4167000,"duration":4000,"startOfParagraph":true},{"content":"get stored that you've been using.","startTime":4171000,"duration":3000,"startOfParagraph":false},{"content":"And then farther up there's this place called the heap.","startTime":4174000,"duration":8000,"startOfParagraph":false},{"content":"We access memory in there by using malloc,","startTime":4182000,"duration":4000,"startOfParagraph":false},{"content":"and then towards the very top of your program","startTime":4186000,"duration":3000,"startOfParagraph":false},{"content":"there's the stack,","startTime":4189000,"duration":3000,"startOfParagraph":false},{"content":"and that's where we've been playing for most of the beginning.","startTime":4192000,"duration":5000,"startOfParagraph":false},{"content":"This isn't to scale or anything.","startTime":4197000,"duration":2000,"startOfParagraph":false},{"content":"A lot of this is very machine dependent,","startTime":4199000,"duration":4000,"startOfParagraph":false},{"content":"operating system dependent, but this is relatively how things get chunked up.","startTime":4203000,"duration":7000,"startOfParagraph":false},{"content":"When you run a program and you declare a variable called x—","startTime":4210000,"duration":7000,"startOfParagraph":false},{"content":"I'm going to draw another box down below, and this is going to be RAM as well.","startTime":4217000,"duration":10000,"startOfParagraph":false},{"content":"And I'm going to look.","startTime":4227000,"duration":2000,"startOfParagraph":false},{"content":"We'll draw jagged lines to indicate this is just a small section of RAM","startTime":4229000,"duration":5000,"startOfParagraph":false},{"content":"and not all of it as we draw at the top.","startTime":4234000,"duration":4000,"startOfParagraph":false},{"content":"If I declare an integer variable called x, ","startTime":4238000,"duration":5000,"startOfParagraph":true},{"content":"then what I actually get is a mapping","startTime":4243000,"duration":6000,"startOfParagraph":false},{"content":"that is stored in the symbol table of my program","startTime":4249000,"duration":5000,"startOfParagraph":false},{"content":"that connects the name x to this region of memory that I've drawn ","startTime":4254000,"duration":6000,"startOfParagraph":false},{"content":"right here between the vertical bars.","startTime":4260000,"duration":3000,"startOfParagraph":false},{"content":"If I have a line of code in my program that says x = 7","startTime":4263000,"duration":5000,"startOfParagraph":false},{"content":"the processor knows \"Oh, okay, I know that x lives at this location in memory.\"","startTime":4268000,"duration":7000,"startOfParagraph":false},{"content":"\"I'm going to go ahead and write a 7 there.\"","startTime":4275000,"duration":10000,"startOfParagraph":false},{"content":"How does it know what location this is in memory?","startTime":4285000,"duration":3000,"startOfParagraph":false},{"content":"Well, that's all done at compile time.","startTime":4288000,"duration":2000,"startOfParagraph":false},{"content":"The compiler takes care of allocating where each of the variables are going to go","startTime":4290000,"duration":4000,"startOfParagraph":false},{"content":"and creating a special mapping or rather connecting the dots ","startTime":4294000,"duration":6000,"startOfParagraph":false},{"content":"between a symbol and where it's going, a variable's name ","startTime":4300000,"duration":3000,"startOfParagraph":false},{"content":"and where it's going to live in memory.","startTime":4303000,"duration":3000,"startOfParagraph":false},{"content":"But it turns out that we can actually access it in our programs as well.","startTime":4306000,"duration":4000,"startOfParagraph":false},{"content":"This gets important when we start talking about some of the data structures,","startTime":4310000,"duration":5000,"startOfParagraph":false},{"content":"which is a concept that we're going to introduce later on.","startTime":4315000,"duration":3000,"startOfParagraph":false},{"content":"But for now, what you can know is that I can create a pointer to this location, x.","startTime":4318000,"duration":11000,"startOfParagraph":true},{"content":"For example, I can create a pointer variable.","startTime":4329000,"duration":3000,"startOfParagraph":false},{"content":"When we create a pointer variable we use the star notation.","startTime":4332000,"duration":4000,"startOfParagraph":false},{"content":"In this case, this says I'm going to create a pointer to an int.","startTime":4336000,"duration":5000,"startOfParagraph":false},{"content":"It's a type just like any other.","startTime":4341000,"duration":3000,"startOfParagraph":false},{"content":"We give it a variable like y,","startTime":4344000,"duration":3000,"startOfParagraph":false},{"content":"and then we set it equal to the address, to an address.","startTime":4347000,"duration":5000,"startOfParagraph":false},{"content":"In this case, we can set y to point to x","startTime":4352000,"duration":6000,"startOfParagraph":false},{"content":"by taking the address of x, which we do with this ampersand,","startTime":4358000,"duration":5000,"startOfParagraph":false},{"content":"and then we set y to point to it.","startTime":4363000,"duration":12000,"startOfParagraph":false},{"content":"What this essentially does is if we look at our RAM","startTime":4375000,"duration":4000,"startOfParagraph":false},{"content":"this creates a separate variable.","startTime":4379000,"duration":3000,"startOfParagraph":false},{"content":"It's going to call it y,","startTime":4382000,"duration":2000,"startOfParagraph":false},{"content":"and when this line of code executes ","startTime":4384000,"duration":2000,"startOfParagraph":false},{"content":"it's actually going to create a little pointer which we typically draw as an arrow,","startTime":4386000,"duration":7000,"startOfParagraph":false},{"content":"and it sets y to point to x.","startTime":4393000,"duration":2000,"startOfParagraph":false},{"content":"Yes.","startTime":4395000,"duration":2000,"startOfParagraph":false},{"content":"[Student] If x is already a pointer, would you just do ","startTime":4397000,"duration":2000,"startOfParagraph":false},{"content":"int *y = x instead of having the ampersand?","startTime":4399000,"duration":3000,"startOfParagraph":false},{"content":"Yes.","startTime":4402000,"duration":2000,"startOfParagraph":false},{"content":"If x is already a pointer, then you can set 2 pointers equal to each other,","startTime":4404000,"duration":3000,"startOfParagraph":false},{"content":"in which case y would not point to x, ","startTime":4407000,"duration":3000,"startOfParagraph":false},{"content":"but it would point to whatever x is pointing to.","startTime":4410000,"duration":4000,"startOfParagraph":false},{"content":"Unfortunately, we're out of time.","startTime":4414000,"duration":3000,"startOfParagraph":false},{"content":"What I would say at this point, we can talk about this offline,","startTime":4417000,"duration":7000,"startOfParagraph":true},{"content":"but I would say start working through this problem, #14.","startTime":4424000,"duration":5000,"startOfParagraph":false},{"content":"You can see there's already a little bit filled in for you here.","startTime":4429000,"duration":4000,"startOfParagraph":false},{"content":"You can see that when we declare 2 pointers, int *x and *y,","startTime":4433000,"duration":4000,"startOfParagraph":false},{"content":"and note that pointing the * next to the variable was something that was done last year.","startTime":4437000,"duration":4000,"startOfParagraph":false},{"content":"It turns out that this is similar to what we're doing this year.","startTime":4441000,"duration":4000,"startOfParagraph":false},{"content":"It doesn't matter where you write the * when you're declaring the pointer.","startTime":4445000,"duration":6000,"startOfParagraph":false},{"content":"But we have written the * next to the type ","startTime":4451000,"duration":6000,"startOfParagraph":false},{"content":"because that makes it very clear that you're declaring a pointer variable.","startTime":4457000,"duration":7000,"startOfParagraph":false},{"content":"You can see that declaring the 2 pointers gives us 2 boxes.","startTime":4464000,"duration":3000,"startOfParagraph":false},{"content":"Here when we set x equal to malloc","startTime":4467000,"duration":4000,"startOfParagraph":false},{"content":"what this is saying is setting aside memory in the heap.","startTime":4471000,"duration":3000,"startOfParagraph":false},{"content":"This little box right here, this circle, is located on the heap.","startTime":4474000,"duration":7000,"startOfParagraph":false},{"content":"X is pointing to it.","startTime":4481000,"duration":2000,"startOfParagraph":false},{"content":"Note that y is still not pointing to anything.","startTime":4483000,"duration":3000,"startOfParagraph":false},{"content":"To get memory—to store the number 42 into x","startTime":4486000,"duration":4000,"startOfParagraph":false},{"content":"we would use what notation?","startTime":4490000,"duration":5000,"startOfParagraph":false},{"content":"[Student] *x = 42.","startTime":4495000,"duration":4000,"startOfParagraph":false},{"content":"Exactly, *x = 42.","startTime":4499000,"duration":2000,"startOfParagraph":false},{"content":"That means follow the arrow and throw 42 in there.","startTime":4501000,"duration":5000,"startOfParagraph":false},{"content":"Here where we set y and x we have y pointing to x.","startTime":4506000,"duration":3000,"startOfParagraph":false},{"content":"Again, this is just like what Kevin said where we set y equal to x.","startTime":4509000,"duration":4000,"startOfParagraph":false},{"content":"Y is not pointing to x.","startTime":4513000,"duration":2000,"startOfParagraph":false},{"content":"Rather, it's pointing to what x is pointing to as well.","startTime":4515000,"duration":4000,"startOfParagraph":false},{"content":"And then finally in this last box there are 2 possible things that we could do.","startTime":4519000,"duration":5000,"startOfParagraph":true},{"content":"One is we could say *x = 13.","startTime":4524000,"duration":4000,"startOfParagraph":false},{"content":"The other thing is we could say—Alex, do you know what we could do here?","startTime":4528000,"duration":5000,"startOfParagraph":false},{"content":"You could say *x = 13 or—","startTime":4533000,"duration":4000,"startOfParagraph":false},{"content":"[Student] You could say int whatever.","startTime":4537000,"duration":4000,"startOfParagraph":false},{"content":"[Nate H.] If this were referred to as an int variable we could do that.","startTime":4541000,"duration":4000,"startOfParagraph":false},{"content":"We could also say *y = 13 because they're both pointing to the same place,","startTime":4545000,"duration":4000,"startOfParagraph":false},{"content":"so we could use either variable to get there.","startTime":4549000,"duration":2000,"startOfParagraph":false},{"content":"Yeah.>>[Student] What would it look like if we just say int x is 13?","startTime":4551000,"duration":5000,"startOfParagraph":false},{"content":"That would be declaring a new variable called x, which wouldn't work.","startTime":4556000,"duration":4000,"startOfParagraph":false},{"content":"We'd have a collision because we declared x to be a pointer up here.","startTime":4560000,"duration":4000,"startOfParagraph":false},{"content":"[Student] If we just had that statement by itself what would it look like in terms of the circle?","startTime":4564000,"duration":6000,"startOfParagraph":false},{"content":"If we had x = 13 then we'd have a box, and rather than having an arrow","startTime":4570000,"duration":4000,"startOfParagraph":false},{"content":"coming out of the box we'd draw it as just a 13.","startTime":4574000,"duration":2000,"startOfParagraph":false},{"content":"[Student] In the box. Okay.","startTime":4576000,"duration":3000,"startOfParagraph":false},{"content":"Thank you for watching, and good luck on Quiz 0.","startTime":4579000,"duration":5000,"startOfParagraph":true},{"content":"[CS50.TV]","startTime":4584000,"duration":4000,"startOfParagraph":false}]}