What happens to local variables when a function ends?
Their lifetime ends. The memory they occupied is freed, and the data they held is destroyed.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Understanding Scope and Lifetime of Variables
Scope refers to the specific block or region of code where a variable is visible, accessible, and can be modified.
Global variables can be modified by any part of the program, making it extremely difficult to track down bugs when data changes unexpectedly.
Block scope means a variable is only accessible within the specific {} brackets it was defined in, such as inside an if-statement or a for-loop.
Still have questions?
Browse all our FAQs or reach out to our support team
