Scope is another concept that’s amazingly similar to your everyday experience. Let’s say you’re at home and ask your mom, “Where are my slippers?” You mom says, “Upstairs.” That’s scope. And you need to understand it to program. Let me explain.

Scope provides the ability to specify the full context or location of what you’re talking about if it’s not immediately obvious.

C++ and C# provide namespaces that help you separate classes, methods, and variables into groups so they don’t cause conflicts. Each namespace is a scope.

We haven’t talked about classes yet but they allow you to group methods, other classes, and variables into a complete unit that acts together. A class also forms a scope.

We’ve discussed methods. Well, methods also form a scope around the variables inside the method. There’s a difference with method scopes though because a method scope also hides everything inside of it from the outside. Any variable defined inside of a method might as well not exist outside of the method.