Global scope refers to the area outside of any blocks or functions where variables are defined. Variables declared in the global scope can be accessed from anywhere in the program.
Think of global scope as a public park. Any person (variable) that enters the park has access to all its facilities (functions, objects) because they are available to everyone in that open space (global scope).
Local Scope: Local scope is a restricted area within a block or function where variables are defined and accessible. Unlike global scope, local scope is limited to specific portions of code.
Namespace: A namespace is a container that holds a set of identifiers (variables, functions, classes) to prevent naming conflicts between different parts of a program. It helps organize and group related entities together.
Module Scope: Module scope refers to the visibility and accessibility of variables within a module or file. Variables declared at this level can be accessed by other modules if explicitly exported but remain hidden from other parts of the program by default.
Study guides for the entire semester
200k practice questions
Glossary of 50k key terms - memorize important vocab
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.