Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q5 of 15
PowerShell - Working with Objects
What will be the output of this PowerShell code?
$arr = @()
$arr += 10
$arr += 20
$arr.Length
A10
B2
C20
D0
Step-by-Step Solution
Solution:
  1. Step 1: Understand array additions

    Starting with empty array, adding two elements increases length to 2.
  2. Step 2: Check length property

    $arr.Length returns the number of elements, which is 2 after additions.
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Array length after 2 adds = 2 [OK]
Quick Trick: Length shows count of elements in array [OK]
Common Mistakes:
  • Confusing length with last element value
  • Expecting length to be sum of elements
  • Assuming empty array length is 1

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes