Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Working with Objects
What will be the output of this PowerShell code?
$array = @()
$array += 'apple'
$array += 'banana'
$array += 'cherry'
$array
Aapple banana cherry
B@('apple', 'banana', 'cherry')
Capple banana cherry
DError: Cannot add to array
Step-by-Step Solution
Solution:
  1. Step 1: Understand how += adds items to arrays

    Using += adds each string as a new element to the array.
  2. Step 2: Output the array variable

    When output, PowerShell prints each element on a new line, so the output is three lines: apple, banana, cherry.
  3. Final Answer:

    apple banana cherry -> Option A
  4. Quick Check:

    Array elements print line by line [OK]
Quick Trick: Arrays print each item on its own line [OK]
Common Mistakes:
  • Expecting all items on one line separated by spaces
  • Thinking += causes an error on arrays
  • Confusing array output with string output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes