Bird
0
0

Why does a variable declared inside a block (like an if or for) in C not exist outside that block?

hard📝 Conceptual Q10 of 15
C - Variables and Data Types
Why does a variable declared inside a block (like an if or for) in C not exist outside that block?
ABecause its lifetime and visibility are limited to that block's scope
BBecause C does not allow variables inside blocks
CBecause variables inside blocks are automatically global
DBecause variables inside blocks are static by default
Step-by-Step Solution
Solution:
  1. Step 1: Define block scope rules

    Variables declared inside a block have scope limited to that block, meaning they exist only during execution of that block.
  2. Step 2: Explain lifetime and visibility

    Such variables are created when block starts and destroyed when block ends, so they cannot be accessed outside.
  3. Final Answer:

    Because its lifetime and visibility are limited to that block's scope -> Option A
  4. Quick Check:

    Block scope limits variable lifetime and visibility [OK]
Quick Trick: Block scope limits variable lifetime and visibility [OK]
Common Mistakes:
  • Thinking variables inside blocks are global
  • Believing C disallows variables inside blocks
  • Assuming variables inside blocks are static by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes