Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q5 of 15
PowerShell - Variables and Data Types
What will be the output of this PowerShell code?
$arr = @(5, 10, 15)
$arr += 20
Write-Output $arr.Count
A3
B4
C5
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand array addition with +=

    Using += adds the new element to the array, creating a new array with one more element.
  2. Step 2: Count the elements after addition

    Original array has 3 elements; after adding 20, it has 4 elements.
  3. Final Answer:

    4 -> Option B
  4. Quick Check:

    Array count after += = 4 [OK]
Quick Trick: += adds element, increasing array size [OK]
Common Mistakes:
  • Assuming array size stays the same
  • Expecting an error when adding elements
  • Confusing Count with length property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes