 Hey guys, this is the functions to lab and I'll be going over question one So for question one, we were given a piece of code and we are asked to Analyze the code and see what the variable foo will be when the code is executed So when analyzing code, I like to make heaps of comments in so I kind of know what's going on so we'll start just Putting in comments for these top two variables. So we know that these are going to be our global variables And we know that a is being equal to five and foo is being equal to zero So now we can jump in here to the setup And we can see that a is now being set to 10 so our global a is now equal to 10 So now we can jump into draw and we're calling bar of a so we know that This is going to be using it's got no local instance, right? So we have to use that global instance And we know that that global instance a is equal to 10. So we're going to be doing Bar of 10 now we come down here in the bar And it's initializing a local instance of a So this variable a is its local instance and that means that this variable can only be used within the function No other function can use that variable So we know that now we have a global instance a and a local instance a so we have to differentiate between those two So I'll just make a note saying we've got this global that's equal to 10 Now we've got this local a that's being Called with the global variable a So it's just being equal to the same thing as the global a so that means our local a is being equal to 10 And then we come into here and we're saying a is equal to 15 So a function is always going to use its local instances before it uses a global instance So this function goes in and checks do I have a local instance of a and we do So that's the variable it's referring to So now the local a isn't 10 anymore now. It's 15 and Then it's not returning anything to us as we can see here with the void And you can see when we come into here it says the value of parameter a is not actually really used So that's just saying that it's not returning anything It's not actually really changing anything because once we get to the end of this function This local instance We're no longer using it. It's like it's not even there So it's just change it's just creating this local instance changing it and then it's done So this function doesn't really do anything So let's make a note here and say nothing really happens So now we can come down here into this next line and Now we can see Again, we've got this Referring to this variable a and there's no local instance of a so we're using the global a And it's going to be equal to that of a so that of 10 So now we can come into here into our that function And again, it's creating this local instance of a So when we call it it's going to say, okay, I'm going to create this local variable. I'm going to call it a So now let's differentiate and say we've got a global a Which is still equal to 10 and then we have a local a Which is being equal to whatever the global a is So this local a is being created and it's going to be set to 10 And then we can come down here and now we know Or we're referring to a again and we're going to update a so a is equal to a plus one So again functions always use their local instances before the global instance So it says, okay, do I have a local instance of a we do so now A is going to be 11 and then this or this function is actually returning something to us So it's returning the value of 11 to us So now we know That a is going to be equal to 11 Now we come down here into this Next line of code and we can see that foo is going to be equal to a So there's no local instance of a within draw So we're going to use our global instance, which is now equal to 11 So I know this gets like a little bit confusing So if you guys have any trouble kind of figuring out what's going on you can always use the debugger So I'll just come in here and I'll put breakpoints on All of our main lines Right and then I can run this And it starts up here at this first line and we'll say go to the next step So now we've created this variable a we've created this variable foo a is equal to five foo is equal to zero Come into here now a is going to be equal to 10 and we can see up here it changed Now we come down here. We're going to call Bar of 10 jump into that and now we can see again just like I said before we've got two instances of a We've got a which is our local instance and this dot a Which is our global instance You can see that that variable a is just kind of created It's set to 15 and then we step out of it and then it's gone So again, nothing happens. We still have a our global a which is 10 and foo which is zero And then we went to call bat a stepped into the function bat Now we've got a which is 10 and this dot a our global instance, which is also 10 Run through that it returned to us a plus one So that was a or that would have returned 11 to us. So now we jump back up into here And if we step to the next line, we can see a gets changed to 11 And now we have foo which is going to be equal to a So now if we run through this We can see that a is just going to be updated again and again every time draws run To whatever its value is plus one and then foo is going to equal that as well So every time we go through to be 11 12 and then we'll go through to 13 14 so on so forth So hopefully this helped And just keep practicing with it if you're a little bit confused