Which statement about global scope is true?

Study for the CodeHS AP Computer Science Principles (CSP) Exam. Prepare with flashcards and multiple choice questions, each question comes with hints and explanations. Get ready for success!

Multiple Choice

Which statement about global scope is true?

Explanation:
Global scope means a variable is defined outside of any function, so it is visible from anywhere in the program after its declaration. That’s why top-level declarations are accessible throughout the program, which is exactly what the true statement is saying. Variables inside a function stay local to that function and aren’t accessible globally. You can also have shadowing: a local variable with the same name as a global can hide the global within that local scope. And where global variables live isn’t fixed across languages; they aren’t typically stored on the stack, but rather in a separate area reserved for global data.

Global scope means a variable is defined outside of any function, so it is visible from anywhere in the program after its declaration. That’s why top-level declarations are accessible throughout the program, which is exactly what the true statement is saying. Variables inside a function stay local to that function and aren’t accessible globally. You can also have shadowing: a local variable with the same name as a global can hide the global within that local scope. And where global variables live isn’t fixed across languages; they aren’t typically stored on the stack, but rather in a separate area reserved for global data.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy