Bird
0
0

Find the problem in this PowerShell snippet:

medium📝 Debug Q7 of 15
PowerShell - Operators
Find the problem in this PowerShell snippet:
$range = 5..3
$range += 2
AThe range 5..3 is invalid
BAdding 2 to an array causes an error
CRange operator cannot be assigned to a variable
DThe += operator appends 2 to the array, no error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range 5..3

    This creates an array: 5, 4, 3.
  2. Step 2: Analyze the += operation

    Adding 2 with += appends 2 to the array, resulting in 5, 4, 3, 2.
  3. Final Answer:

    The += operator appends 2 to the array, no error -> Option D
  4. Quick Check:

    += appends elements to arrays in PowerShell [OK]
Quick Trick: += adds elements to arrays, no error [OK]
Common Mistakes:
  • Expecting += to add numbers arithmetically to arrays
  • Thinking range operator output is immutable
  • Assuming 5..3 is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes