21:Everything u need 2 know about pointers -Richard Buckland

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Better than Binky.

👍︎︎ 8 👤︎︎ u/comedian_x 📅︎︎ Nov 21 2010 🗫︎ replies

Richard Buckland is a legend. Awesome lectures.

👍︎︎ 7 👤︎︎ u/moolcool 📅︎︎ Nov 22 2010 🗫︎ replies

Finaly a submission in r/programming that actually has something to do with programming.

I was amazed that I knew everything he talked about.

Java in college makes people oblivious to memory usage.

👍︎︎ 17 👤︎︎ u/Bedeone 📅︎︎ Nov 21 2010 🗫︎ replies

Now i want a mars bar.

👍︎︎ 4 👤︎︎ u/fm_am 📅︎︎ Nov 21 2010 🗫︎ replies

That class was loud as hell. He is a patient professor.

👍︎︎ 4 👤︎︎ u/Iamien 📅︎︎ Nov 21 2010 🗫︎ replies

Is the answer to, ((&(&(&(((x))))))), //what is this, LISP!? the problem he showed about 16 minutes in equal to 4?

x = 2
*x == 4
**x == 11
***x == 6
&***x == 11
/* won't compile
    &&***x == 4
    &&&***x == 2
    *&&&***x == 4
*/

EDIT: proof

You can't get the address of an address in C/C++. This makes sense because whats returned from &x isn't stored in a place you should be able to access, and thus, are not allowed to find the address. I was thinking that the compiler would negate &* but that would be even more confusing.

👍︎︎ 5 👤︎︎ u/jayd16 📅︎︎ Nov 21 2010 🗫︎ replies

Upvote for 'naughts and crosses' instead of 'tic tac toe'. Other than that, I was pretty disappointed as the topics discussed in this video were pretty basic and didn't even cover function pointers. I'd hardly say that's everything I need to know about pointers.

👍︎︎ 5 👤︎︎ u/ceilingpyro 📅︎︎ Nov 22 2010 🗫︎ replies
👍︎︎ 3 👤︎︎ u/wsppan 📅︎︎ Nov 22 2010 🗫︎ replies

At first I was like tldr .. and then I am bringing food to watch the rest of this

👍︎︎ 3 👤︎︎ u/[deleted] 📅︎︎ Nov 22 2010 🗫︎ replies
Captions
in awesome place so I had a lovely time while I've been there Romania and I'm going to go pick them up from the airport so afternoon so I won't hang back a long time after today's lecture if that's okay and unfortunately it means I missed the sumo thing which is very sad they will record it and I'll watch it on movies but I would have liked to come along and support you guys in the sumo calm but so anyway since now just by while I was in fact giving the last lecture I began to feel quite nausea s-- nothing to do with you guys or the content of the lecture and then I go incredibly sick sicker than I can remember ever being before and I was pumped up with all sorts of drugs and things and I still went to Hong Kong and hopefully haven't started another sounds equivalent and it meant there are a couple things I wanted to do before I left that I didn't get to do so let me try and catch up with those things now you'll notice I hope that I've been putting up tutor and lab solutions furiously in the background since I've been back so there's lots more tutoring labs up and I hope by the end of this week to get them all up so everything's caught up and I also hope to put up a page or a series of self-test exercises and a little tutorial for those who are still not completely happy with the machine code just so everyone gets up to speed on that because I at the end of this week I would like everyone to be up to speed with machine code now let me just connect I think everything's working now I had an enormous pleasure on the weekend or on Sunday after I got back looking at looking at Tim's lectures and it was amazing what a good consequence of being out of video the lectures I was able to see exactly what he did and how's that light a bit dark is that too dark this is this hard like ah ah technology is working thank you and did that uh last step connect to the internet so I was able to see everything that happened so I'd like to start today's lecture with a little bit of revision because one advantage I had Shh being able to watch the lectures was I could watch you guys be moving and being restless and I could work out what bit you got and what bit you didn't get it's really good in fact I'm proposing next year that we were students up with electrodes so the lecturer considers information so it looked to me like all the Monday stuff went perfectly well and was absolutely brilliant and fantastic and on the Wednesday looked like a lot of people got a little bit stressed I could send stress in the first 20 minutes of the lecture when pointers were being done and that swap piece of code was run and things like that so I thought I'd just touch on some of that again oh now why can't that pay to be displayed that's not good perhaps if I use Firefox yeah we got shh-shh-shh and I'll oh I am logged in off where to log out it's been logged in all this time Wow where's here we are here's today's lecture so first of all my plan is approximately to spend the first half of today's double lectures revising pointers and address of and talk about a couple of interesting issues that rise up then I plan to show you a magic trick which would be fun then I plan to tell you something interesting about estimation and then I'm hoping that we'll spend the second half of today doing a worked example using arrays and also talking about the tasks too so that's our plan for today now the key I think behind the whole pointer thing is this issue that I know I keep going on about but let me just go on about one more time the distinction between talking about something literally itself and talking about a reference to something the old toilet sign yep the toilet sign is not the toilet so if we just go to the full bit machine code for a second and assume we've got 16 addresses and they're labeled 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 we've got 16 memory cells and they all have an address and the address is a number each memory cell can also have contents I wish I had more colors all right I'll do it in different fonts how about that that the contents are also numbers say between 0 and 15 so the contents might be 7 2 4 8 11 10 3 5 10 eight two six one zero o-5 can everyone see that every cell has an address and a value now normally when we talk about things it's clear which we mean so we just unconsciously disambiguate which of those we're talking about and everything makes sense but I'd like I'd like us to make it pay too explicit attention to it because sometimes that disambiguation you can't do explicitly though you can't do unconsciously going to do it explicitly so let's for example pick this cell here and say that in this cell here which has address 10 and has value to this cell here suppose I'm going to call that X and on this system X is an int and in sanh this system store numbers between 0 and 15 so whenever I'm talking about X I mean this cell what do I normally mean when I say X if I say tell me X what do I normally want you to tell me yeah normally when you say a name that's great when you say name normally you mean the value that's the normal thing you mean in C it's exactly the same a variable corresponds to an address in a location in which an address corresponds to a location in memory name corresponds to a location at cell in memory funny man said that right so when you say X in a C program and X has previously been declared as an int when you say X you normally mean the value stored in this location so X normally means the value of that cell if I wanted to talk about the address of that cell how do i disambiguate that and see how do i foresee to tell me the address of the cell not star amperes an ahh I can do it I'm actually going to do an Amazon today today is going to be my first day I've done an amputee I knew I could do it I knew I could and you have to do ampersand X means your dress of X X means the value of x you must burn this into your brain now this isn't too hard to understand but sometimes when we want to talk about a cell we haven't given it a name if we've given it a name everything's easy and we can just refer to the cell by the name but sometimes we haven't given it a name how else can I refer to this cell suppose I wanted to refer to this cell here which happens to have the name Y but suppose I didn't know that and I want to refer to this cell how could I refer to it without its name yes I could say I'll say it in English first that's dead right what you said I'll say in English worse I'd say the cell at address 7 and to make that short and C we write star 7 now so Y and star 7 are really the same can you see they're just different names for the same cell and when I say star 7 do I mean the address of this cell or do I mean the value of this cell the value because that's our default when I talk about a cell I normally just mean its value so star 7 means the value of this cell so if I said to printf % D what am I trying to say o star 7 what would it print out we print out a 5 now you might ask yourself why bother why don't we just use names for everything why do we want to be able to talk about things without using their names talking about something without using its name in this way means we're not talking about it directly we're talking about it indirectly and it's called indirect addressing so when I talk about indirect addressing I mean I'm referring to something without giving its name so I could use indirect addressing here I could say the person sitting 3 rows back to see 10 what is your name Chan CH Chen okay I've I've specified that seat and I mean the value of that seat which will be say the person sitting on it because that's a default when I talk about a cell I'm in debate so I'm meaning the value of Chan but I didn't have to say Chan's name because I referred to that location in a more roundabout way that's indirect addressing I could put a number on every single seat and I could say the person sitting at seat 57 I'd be indirectly addressing say you what's your name Radhika I'd be in directly addressing Radhika I could direct address her directly by saying Radhika or I can say hey the person sitting at 67 or I could just say hey you that's favorite lecturer speak we prefer indirect addressing yo out of my room but it's still another yes oh if you don't initialize anything anywhere this is normally rubbish in it and maybe the compile is clever and fills default values in but should we rely on that no way and even if we know the compiler does that should we rely on that no way never never just assume things will magically work let's make them explicit unless there's a huge cost in it let's make it explicit so you now know how to use a star hopefully and you know how to use an amp isn't what if I was to say this printf ba ba ba ba ba ba star X Y does that mean tell me what you think it will print out no you think it yourself don't call it up well not we using this example of you okay how does he interpret this C is so once you understand how she does things it follows the same rules every day there's no mystery about it so just have to know the rules and we can work everything out star is an operator so we've got an expression here the operator is applying to a value we have to evaluate the value first what does X mean when we say X in C C what's that shorthand for the value stored at X remember that's what we mean when we say the name we mean the value stored that's the default before it was obvious it's less bit less obvious now so thank heavens we made it clear what is the value stored at X this was X so the value stored at X is 2 so this is really saying what star 2 what is star 2 for a dress number 2 contains the value 4 so this would print a fall that's it it's no more complicated than that it's that's complicated but that's as complicated as it is so if you understood what I said and you write good notes about it and you just burn it into your brain and try lots and lots of examples you now understand everything you need to know about pointers Tim did talk about pointer arithmetic we're not going to do pointer arithmetic in this course pointer arithmetic read backwards sounds like country and western music so we're just not going to do it okay yes if I put an X there no if I oh yeah what would it print out if instead of printing out I'm going to do a separate example down below but I'm going to be lazy data data that up comma X what would that print out well this is going to print out X when I talk about X what do I always mean when I say X the value of X what's the value of x 2 what if I said print out data that other than a comma ha effortlessly flirt lessly X what's that going to print out 10 now here is a hard one for you this is homework if I said print out star Amazon and present Amazon star star star X what am I talking about it's a number we're just going to have to work it out I'm not sure how C parenthesizes these things so let's put the parentheses in explicitly look this looks like an incredible exam question this is definitely gonna be an exam question all right so let's let's work it out well should we work out this ridiculous exam question yes all right what's X - all right what star X X is - let's double check that yes star X means what's stored at address 2 which is 4 all right so this is 4 so what's star 4 thank you what's star 11 let's just check that star 11 I should check it is 6 isn't it ok star 11 is 6 what's the address of 6 that six isn't it no no this is saying what's the address of this number oh heck I don't even know where that numbers well oh bloody hell that's confusing it looks to me like maybe it only makes sense if you put the amazons first and then the star second I think try it out try and see okay we've now moved into territory that's freaking me out of it it's not it's not it's not going to do a magic trick it's not going to search through memory trying to find where 60s in return its address see it doesn't do any work it's comparatively lazy it wants to know the address of this six this six is in the middle of an expression so I don't even know that it has an address so it's probably just rubbish so it's a rubbish Exam Question so when you see this question in the exam just write rubbish all over it and anyone that tries to answer it will waste hours and hours and hours and hours and you'll be well ahead of them okay does everyone understand all of that are there any questions about addresses and pointers and values yeah oh you haven't seen a practical use oh yeah look I like I like you what's your name William when your master really good have I spoken to you before with him what's your surname Chan or something soo okay I recognize your face suddenly came to me Williams asking a really key question which we should always be asking which is what's the point of learning all this if I could rephrase that I think the really good question to be asking here I really good question be asking here is what's the point of indirect addressing I cannot see any value in indirect addressing hang on a second when you when everyone's on top of indirect addressing or we can do something wonderful with it right away in fact I'll do something wonderful I will do something wonderful right now but B there's something even more to in fact more wonderful things we'll see that we can do with it that occur later in this course in fact most of the really wonderful ideas in the course are going to need to be able to do this in directness in addressing are there any more questions about pointers and dresses okay let's look at number one I said there were three three things let's look at number one for really neat thing to do with pointers and addresses and it's this and Tim's sort of said this already but H is that muttering is that good muttering are you explaining pointers and addresses to each other or is that bad muttering and you're doubling and doubling and doubling and trying to work out how many Mars bars I owe you look if everyone how many do I owe you 256 it cannot be 256 because there was like in week one I promised it on the first day tonight and I promised I would deliver it on the second day when I didn't deliver it on the second day I owed you two and then we had week two then we have week three I'm had week four we have week far I couldn't have delivered in week five so you can't penalize me for that it's only only get penalized when I forget to bring it along so one two four eight 16 32 16 hey what is that 64 are we right we're only here now oh nice sleight of hand didn't trick you very much that's week 1 week 2 week 3 week 4 week 5 which doesn't count in our week 6 so we go 1 2 4 8 16 32 64 128 someone wrote in thinking next week allow you a thousand by the end of the course I low a million this is the amazing power of doubling that is astonishing well okay let's just erase this very quickly and move on look um the thing that Tim pointed out at the end of the lecture is is really the key first use of pointers in C when I have a function of running my main four I'm going to draw a picture of memory okay when I'm running my main function the codes up here right and it is probably storing all its data in a stack front in a frame down here low in memory and if the main function calls another function whose code is up here it's going to be storing its data somewhere maybe down here maybe above it well actually let's say it's above it because that's more likely to be where it's stored and that's got my sub function what does that do that does something who knows what it does there's some task task stores it stuff in here now I've said before one of the really neat things about functions is this notion of scope this this wall abstraction a wall around them that stops while mains being executed it can't fool around with any of the variables of task and when the subtasks being executed it can't fool around with any of the variables of main it can't because they've all their data stored in their frame and that's the only data they're allowed to use certainly how do they know about now let's suppose that there was a really good reason four tasks to fool around with some of Maine's data notice I'm not saying there is a really good reason we'll have to later on think gee is this a really good thing to do under what circumstances hey hey people talk but suppose the task did want a full round with Maine's data when may is it how can how does Maine communicate with tasks well suppose main calls tasks and it's got two variables x and y and they're both in sand it passes them in what happens when main calls tasks what happens to the values of x and y suppose x stored the value 10 and y stored the value 100 it copies them so these x and y here were stored somewhere in here x and y which does ten and a hundred are copied into here 10 and 100 and in here you might have given them the same names X and while you might give them some other name and hopefully by now you've worked out it doesn't matter what name you give them they're separate and if you fooled around with the values inside tasks is it affecting main at all no so what's so far the only way task has of communicating back with main a return value at the end of task at the end of the code for tasks it'll say something like return 0 and that value gets passed back to main so so far the only way of task sending data to main is by returning that data and that's that's really good for a number of reasons but suppose we wanted to break that suppose we wanted tasks to be able to fool around with Maine's data directly suppose we want two tasks to be able to get to x and y here and actually swap them round inside the memory here or suppose we wanted to be able to just take these values and change some of them mysteriously so when the function returns main has been altered in some way this is clearly what what do we describe this sort of behavior as being someone said what was it no it's not necessarily bad but it is usually bad it rides it rhymes with ride a Bret what what could it be something that rhymes with ride a Brecht hide my Brecht I've got a book of Brecht it's a hint it runs with side effect the phrase I'm looking for side effect thank you very much it's a side effect if calling task in addition to returning something Falls around with main task has a side effect and we remember for various reasons that I hope I've explained up until now and if I haven't Grill me before the end of the course side effects are normally seen as being really bad but suppose we wanted to have a side effect suppose we want to toss about a full round with main stuff how can it it appears impossible but no longer is it impossible someone that knows tell me put up your hand wave at me how how no yeah no you on the end point is how could you use point you've got a google shred on so we can't have Google in here this is private nothing between these walls ever leaves these walls oh you so how can we use pointers to let task full round with main the variables are - sorting memory yeah they're stored inside mainframe at location say a hundred and ninety one thousand ninety two 1093 yep how can task access those locations it doesn't know where those locations are who can tell it where those locations are main so when main calls task if main instead of giving task some information that was like copied values if main told tasks the address of some of its own secret locations tasks can go to those addresses suppose task looks like this suppose task gets passed in an X and we once an X and what suppose task gets passed in p1 and p2 and suppose they're the addresses of x and y if task wanted to fool around with those addresses how would it refer to them it doesn't know the names X&Y they're not in its scope but how can it refer to those cells if we talked about star p1 it's really talking about X if Maine passes in X&Y Oh if Maine pass what would Maine have to pass in the address of X the address of Y if Maine passes in the address of X in the address of Y TAS can access those cells by calling them star p1 and star p2 does that make sense ok this is neat thing number one about pointers does that convince you a little bit with yeah yeah it lets you fool around with memory inside someone else's stack frame now whether that's good or bad that's a separate issue all right so we've done oh and when you can change things like this in some languages is called the via parameter the things you're passing in can be changed let's see we don't call it that but if you program in Pascal this is a VAR parameter yes yes oh yeah how do you actually call it well actually maybe you can tell me I reckon you can work it out I'm inside main in main bar Bubba I'm just about to call task and I want to let it fall around with my X&Y I've got an index I've got an ink why I want to let task fool around with it I go task what do I have to pass into it what does it need what does task need to know got it how do I write the address of X how do I write the address of Y you got it so when we pass it in we pass in the addresses now now we're in task task voi it doesn't seem to do anything so void task period parameters what's it expecting it's not expecting ence what are you giving it addresses events do you remember how we say that we say int star p1 int star p2 that's how we tell it where it's expecting pointers we're passing in addresses those addresses are we also caught pointers in C we read this it's like a little game star p1 is an X isn't in this says star p1 isn't in you guys taught me before what star P 1 is what star p1 no no p1 is the address of X so star p1 is is X itself yeah is X and what type is X and int so star p1 isn't it so that's right the contents of the address of p1 is in it this is what we're telling it in other languages you write it like this int star P 1 you say p1 is a pointer to an end but in C we don't say that we say the thing that p1 points to is an end we put the space in a different spot you could put the space here you can put the space here C is going to forgive you if you put the wrong spot but don't it'll forgive you in small examples in more longer or complicated examples you can actually trick yourself trip yourself up in the wrong spot so star p1 means this is an address of something this is the contents of that address which is an int which is in it which is in it that's what I think does that make sense does that answer your question and inside the code down here whenever we want to refer to X what do we have to say star p1 so if I wanted to increase X by 1 what would have to say something like star p1 equals oh yeah I could do plus plus but let's do I'm starting 1 plus 1 let's do it like that first now in this is a rare example in C where it allows you to put an operator on the left hand side it really just in regards these two things as talking about a single memory location normally all the operators have to go B now we could say star p1 plus plus now what are we relying on yeah we're relying to the fact that this operation gets called here are 2 operations being applied to this value we're relying on yeah we rely on this all over the place we rely on the fact that this happens first and then this happens second we if it happened the other way around we'd be in the poo can you see if it increased the pointer by one first and then fact what was there instead of increasing X by one it would return the value at what's ever 1 after X which is why ah no I luckily see does it that way and that's sort of an idiom no it doesn't it does it the other way well done cool so but for me I like putting things in brackets because even when I think I've got it right sometimes I've got it wrong yeah in brackets it does the right thing so here yeah we're assuming this we're assuming this has higher precedence in the plus 1 that's probably okay but you could put it in brackets if you want it okay yes how do you don't have to pass it back to me if you want it to pass something back you'd say return but we don't have to what we're saying here is go to the address that p1 points to yeah so this is literally talking about the X that's hiding inside main and it's directly operating on that address so when it finishes that's why we call it a void it doesn't actually return anything it's already done its evil work you know normally a function does its work and then says and here's the output but you say do some work she goes away and I say if you finished he said yeah man I did a long time ago well you were still talking to me okay that's what happened it's happening in the middle it's updating while it's running makes programs much harder to analyze mathematically which is one of the reasons that it's slightly frowned upon and it's not only Hallett analyzed mathematically for us to see what's going on it allows more interactions it makes things more confusing confusion is always bad in a program there's always enough confusion in herre in the problem we don't need to add more in the particular way we solve it so we normally strive to minimize confusion so side-effects tending to be more confusing are often avoided wherever possible avoid a river possible okay so you've seen now Hey how will you start and how we use Amazon be a good example of why it's neat because this lets us change things and from what inside one function we can change things inside another which essentially lets us return more than one thing at a time you might be itching to return two things from a function up until now we've only been out return one now we can have a function affecting as many 50 cells or 60 cells of memory can affect as many as at once using pointers both a blessing and a curse because the more powerful you make functions the more chance that they can suffer okay so we passed by reference how we do it why we do it okay I've just said why all the whites bad about it but people still do it what's good about it what's good about did I say ones passing by reference ones passing by Firefox is ready to install let's just-okay pass by value is what we normally do and see that's when things are copy so when you pass information to a function it gets copied across pass by reference is when you pass something in you both share that same thing and if the function alters it it alters the original that you've got passed by value means you give them a copy pass by reference means you give them a reference to the original thing you can both access the original thing so this is called pass by reference pass by value well pass by value makes a lot of sense but pass by reference which I've been pulling up until now and we looked at how to do it it does have some advantages why might you pass by reference why might you not want to do that copy yes yeah yes that makes sense what he said was the example he gave us a game I'll even use your example it wasn't the one I was going to use but - better than mine suppose you've got a game and in this game there are entities I haven't played a computer game for a long time someone told me a random computer game pac-man oh man you're from my generation ok pac-man needs to remember what color it is what sort of teeth he's got which direction is heading in is a couple of bits of information the pac-man means to know you might want to call a function and pass it the information about pac-man so the function can work something out like did he just manage to gobble the fruit in time or something like that you've got a did you gobble the fruit and time function so you need to pass all the pac-man information in if the pac-man information is a whole lot of information passing it in doing that function call is very expensive because it all has to be copied into the stack frame of the other function now the other function use it that it all gets thrown away you you would think of a more elaborate game maybe which maybe though the thing you're trying to pass in might be a megabyte worth of information yeah the thing need to be able to scan over and get some of that megabyte worth of information but it doesn't need much of it just needs a few little bits of it it's a real pain you have to copy the whole megabyte into the function then the function runs because that's waste time and actually there's a downside of that because programmers start not wanting to use functions then they start saying this function calls too expensive I'm just going to do it in main and they make their main bigger and bigger and bigger because I don't want to have because functions are too expensive and that's a disaster for your program you don't want a big main it's complicated it's not going to work you want to break lots of functions and get all the advantages of functions so pass by reference lets us pass big chunky objects down without having to copy them now in C you haven't seen many big chunky objects you've seen instant doubles and floats and chars they're tiny who cares whether they're copied or pass by reference you have seen now one big thing what is that a raise an array you could make an array that's a minion it contains a million elements each of those a million elements might be I don't know it might be an int a million ends so that's 4 million bytes say if you've got 4 byte sins that's a huge thing for million bytes you want to pass that array into a function do you want to pass it by copy or pass it by reference you probably want to pass it by reference because that probably is too much of a cost now in a decent programming language and I'm not here slagging C but in a decent programming language the programmer would be faced with a choice and the program would say well in this case I want to pass it in by reference rather than by copying because going to be too expensive to copy it in C took a different path C said if you got an array I reckon you always want to pass it in by reference so C always copies or passes are razing by reference and how it does that is a little trick that Tim mentioned to you that whenever you pass an array into a function suppose you've got an array called I know the heights Heights is some array if you want it to pass Heights into a function and you said I don't know a called task on Heights that's my function call C automatically replaces that with a pointer to the first element of the array and it doesn't attempt to copy it it just copies the pointer in and anyone inside the function that accesses the array is accessing the original array which is sometimes good and sometimes a pain because sometimes you may actually want to give someone a copy there right for example if we were writing a game and you were writing a player and you were writing a player and you were writing a player and I wanted all your players to interact with each other in play and all the game state was stored in an array and you guys needed to see the gamestate if I gave you each a reference to the game state what could their functions do they they could fall around with the game state I say here's the array of all information about the game promise you won't change any of it okay oh sure yeah yeah just give it to me on the player oh by the way I've got 900 rides now and Oh where's he hiding I'll just look in the eraser oh he's hiding it and they get access to everything that's a real pain you do often want to compartmentalize information away from your functions you don't necessarily wanna get in the whole thing you don't really want to be able to change the original thing when I give you a transcript it's passed by coffee you go up and pay five dollars to get a uni transcript that's a copy of your transcript it would be insane if I gave you the actual pointer to the Uni transcript database pointer thing so here's your transcript don't change it though okay does that make sense yeah okay no it's sad but they go okay so the so we've seen passing rate so that's all the revision I wanted to do now where are we up to we've still got a quarter to the hour so I wanted to show you this really cool magic trick because while I was in Hong Kong I was trying to teach myself magic because I think magic is very cool so I got a magic box and a magic wand and we're now going to do some magic to run ready for the magic pull 200 miles box out of my pocket I don't know what you're talking about now here we go okay go go oh oh my mic them ah everything's not much sorry guys we've had a technology breakdown you go here you go here ha ha thank you you're may I make a document camera disappear its usefulness disappear all right I'm gonna need a volunteer to check I'm not cheating because I'm not gonna be able do it on the document camera can I have any impartial volunteer Oh me okay Richard you can be the impartial volunteer now hang on people might suspect that you told me don't tell me Richie Radhika come up here come up here you can be the scrutineer to make sure I'm looking out sheet right now I've got my magic wand mm tirely magic it's also silver I've got my magic box inside the magic box I have some magic cards put clear them out here all right is it Ricky reticular everyone what's on the three cards tell them the names of the cards the four of diamonds four of diamonds at the ace of spades the ace of spades no that's fine the Queen of Hearts the Queen of Hearts okay does everyone remember four of diamonds ace of spades Queen of Hearts now I know which one you're going to pick because you're going to pick one of them the mate I don't know the magic one knows the magic one knows everything okay tell me when to stop what did you stop what did the magic one stop on the four of diamonds please open the magic box so everyone I glutenin what is it what is it the four of diamonds thank you very much well done would you say that is the most impressive magic trick you've ever seen do you want you wanna see it again okay I need another volunteer so running huh I volunteer from you you yep yep come down come down okay okay just check the magic boxes ready okay tell me when to stop now you sure you didn't want this up on the floor okay what's in it David turn over the ace of diamonds clubs what does it say turn over the other cards what do they say nothing the only card that said you will pick me is the card we pick the SS paint now a good magician never reveals his trick but do I want to have a third volunteer is it yes please come down well can you get can you get down okay okay tell me what you want me to stop take my magic wand turn it over what does it say you will pick the plane thank you thanks so much now this is a demonstration of what I like to call make sure you get the spec well in advance and get it pinned down because if someone is free to change the spec they're free to change the parameters of the problem you're doomed you must get them to commit to the problem you're trying to solve before you try and solve it yes so when you get tell suit oh oh yeah look we will we will get tasks too soon we're going to have a break in five minutes and I wanted to do some quick stuff over the break so you guys got to help me I had this idea that we would demonstrate the use of arrays I'm not going to do a little bit of array work and I thought rather than just sort of talking about arrays we'd write some code our 2d arrays like a grid or something oh I what would that make it game do pac-man I want to do something we have enough time to write in class so text-based pac-man well be awesome wouldn't wouldn't be any good so I went on a game we could do it in a grid look at grid can also be represented as a single array you haven't seen grids I don't necessarily want it well let's do a grid based game okay can anyone think of a simple grid based game or a puzzle like a crossword or something like that Ches Ches Ches might be not to cross this is good who wants knots and crosses any other any other guesses Sudoku who wants to do Co oh how come why the interest in Sudokus oh why not hun has to do okay all right let's do Sudoku Shh and promise we won't tell one nine-one-one anything we do okay so in the break I'll I'll set it up I'll start writing the file it's what I want to do before the break and then when we come back from the break we'll write a Sudoku what you wanted some of the plays again something solves the game a solver will write a Sudoku solver together using a raise after the thing okay now Shh before we take a break you use just about to have a break but hey hey guys shhh no trip is any good without presents so I brought you some presents and so I would like if everyone could come down and just take one of these I have 256 Mars bars in here so if everyone could just come down and take one they're from Hong Kong but I'm using Li I'm using you should have seen me taken through customs amusingly they're actually made in Australia imported telling a book but you can see look that is definitely Chinese yeah it's definitely from like a Chinese shop but okay so go if can everyone please take one just take one because there's only enough to go round for one each thank you - possibly yes sodoku so that's a recently our task oh no it's trivial we'll do it we'll knock it over in the lecture yeah yeah yeah possible know what breathless oh well you when Z what sake let me think about how we can do it I need a couple UNSW that like this computer crashing things I was meant to be the hardest for each one I'm like I had a thousand and five minutes that move high school yes question now is the final some final question two thousand five one thousand five yes I wasn't doing it in 2005 I think I stopped in 2004 so would have been someone else yeah it's not another's questions but yes you'll get me some of those questions I'll set them sure sure but we'll do this now yes yeah you wanna come over in here but have a look for a bit yes um but what my convention I usually start my studies brings a touch well yeah yeah yeah yeah I mean that's how Pascal works but it's not he'll see works see plays this game that this expression evaluates to that and now the reason I mean she will forgive you if you put the star over here it just thinks how you put the space in the wrong spot and it just moves it across for you
Info
Channel: UNSW eLearning
Views: 508,124
Rating: 4.9087481 out of 5
Keywords: pointers, indirect, addressing, pass, by, reference, value, richard, buckland, UNSW, computer, science, comp1917, university, lecture
Id: Rxvv9krECNw
Channel Id: undefined
Length: 48min 28sec (2908 seconds)
Published: Fri Apr 25 2008
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.