When programming, it is important to know which variables you can use where. I'll explain.
Let's say you declare a global integer x, and you define a function myFunct(). In the definition of myFunct(). You would obviously be able to use this integer x. But does it go the other way around? That is, can you use variable declared inside a function outside the function?
Simple answer. No.
When you call a function, the "flow" of your program halts so that it can go run your function and then return with the results. Let's say we have a function add2()
int add2(int x)
int y = 2;
Yes, I know there's no reason to declare this variable y, but it's for the sake of the example. In this case, The variable called y only "lives" until the end of the function. After that, this variable no longer exists, and hence it can no longer be referred to (Things like this can be overcome using the "static" keyword. I'll mention this sometime). In fact, this variable x no longer exists either. x is just a temporary holder for a value that is used while the function is running!
Functions are just one example of where knowledge of a scope could be useful. Let's say you were running a for loop.
Clearly, this is just an average for loop. Runs whatever code between its curly brackets 5 times. Now check this out:
//do other stuff
Can you see the difference?
The difference is that in the first case, the variable i would be usable even after the for loop was executed. In the second case, i "dies" as soon as the loop terminates. Personally, I like to use the second method just because it allows me to use the same identifier for all my loops (assuming they're not nested) without fear of that identifier already being declared and used for another loop. I also just find it neater ;)