Bird
0
0

What is the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Variables and Data Types
What is the output of this PowerShell code?
$arr = @('apple', 'banana', 'cherry')
Write-Output $arr[1]
Abanana
Bapple
Ccherry
D1
Step-by-Step Solution
Solution:
  1. Step 1: Understand array indexing in PowerShell

    Arrays start at index 0, so $arr[0] = 'apple', $arr[1] = 'banana', $arr[2] = 'cherry'.
  2. Step 2: Identify the output of $arr[1]

    The code outputs the item at index 1, which is 'banana'.
  3. Final Answer:

    banana -> Option A
  4. Quick Check:

    Index 1 = banana [OK]
Quick Trick: Arrays start at zero; index 1 is second item [OK]
Common Mistakes:
  • Thinking index starts at 1
  • Confusing item values with index numbers
  • Expecting all items printed instead of one

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes