LearnFrenzy
Sign in Take a free test

C Variables · Variables MCQ · Question 9

Scope vs lifetime of a variable in C Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

Which statement correctly distinguishes scope from lifetime?

  • A They are the same thing
  • B Scope is where the name is visible; lifetime is when the storage exists Correct
  • C Scope is for globals, lifetime for locals
  • D Lifetime is measured in lines of code
Correct Answer: Option B

A static local has block scope but static lifetime; heap memory has no name (no scope) but lives until free(). Keeping the two ideas apart explains static locals, dangling pointers and leaks.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links