C - Scope, Lifetime, and Visibility of Identifiers

Scope

Scope defines the region of a program where an identifier (variable or function) can be accessed.

Types of scope:

  • Block scope

  • Function scope

  • File scope

Lifetime

Lifetime refers to the duration for which a variable exists in memory during program execution.

Types:

  • Automatic lifetime

  • Static lifetime

  • Dynamic lifetime

Visibility

Visibility determines whether an identifier can be accessed from other source files or modules.

Importance

Correct use of scope and lifetime:

 

  • Improves memory efficiency

  • Prevents naming conflicts

  • Enhances modularity