C++ FunctionsLesson 28Free preview
C++ Scope
This lesson is part of C++ · All levels
Summary
This lesson explains scope, the area where a variable name or function can be accessed. Local variables only live within the block where they are declared, whereas global variables can be accessed from anywhere in the file. Understanding scope helps to avoid name conflicts and bugs that are difficult to track.
Key points
- Scope specifies the range of access to a variable or function name.
- Local variables are only visible within the block where they are declared.
- Global variables are declared beyond all functions and widely accessible.
- The local variable covers the shadow of the global variable with the same name.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.