Difficulty: Easy
Correct Answer: 2 and 3 only
Explanation:
Introduction / Context:
This item focuses on where arrays and their elements live in memory and what type the array instance is. Understanding stack vs heap and System.Array inheritance helps avoid common misconceptions about performance and allocation.
Given Data / Assumptions:
Concept / Approach:
The local variable a is a reference; local references typically live on the stack (implementation dependent, conceptually a local). The array object, which holds its elements, is always a heap-allocated managed object. Arrays are instances of preexisting runtime-provided types (such as System.Int32[]), which derive from System.Array; we are not creating a new class per declaration.
Step-by-Step Solution:
Verification / Alternative check:
Inspect a.GetType() to see System.Int32[]; heap allocation is observable with GC behavior and object identity semantics.
Why Other Options Are Wrong:
They either place elements on the stack, claim class creation, or make storage conditional on size, all contrary to CLR rules.
Common Pitfalls:
Confusing the reference variable's stack storage with where the array and its elements reside.
Final Answer:
2 and 3 only
Discussion & Comments