Skip to content

Scope and Lifetime ​

Scope determines where a name is visible in the program, while lifetime describes the period from an object's creation to its destruction.

cpp
int main() {
  int outer{1};
  {
    int inner{2};
  } // inner's lifetime ends here
}

Subtopics ​