Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q4 of 15
PowerShell - Working with Objects
What will be the output of this PowerShell code?
$arr = @('cat', 'dog', 'bird')
$arr[1]
Acat
Bdog
Cbird
DIndex out of range error
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing

    PowerShell arrays use zero-based indexing, so index 1 is the second element.
  2. Step 2: Identify element at index 1

    The array is ['cat', 'dog', 'bird'], so element at index 1 is 'dog'.
  3. Final Answer:

    dog -> Option B
  4. Quick Check:

    Zero-based index 1 = 'dog' [OK]
Quick Trick: Arrays start at index 0 in PowerShell [OK]
Common Mistakes:
  • Assuming index starts at 1
  • Confusing element positions
  • Expecting error for valid index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes