Bird
0
0

What is the issue with this PowerShell code snippet?

medium📝 Debug Q6 of 15
PowerShell - String Operations
What is the issue with this PowerShell code snippet?
$part1 = "Hello"
$part2 = "World"
$combined = $part1 + * $part2
Write-Output $combined
AThe '*' operator cannot be used for string concatenation in PowerShell.
BThe '+' operator is missing between the variables.
CVariables must be enclosed in parentheses when concatenating.
DWrite-Output cannot output concatenated strings.
Step-by-Step Solution
Solution:
  1. Step 1: Identify the operator used

    The code uses the '*' operator between two strings.
  2. Step 2: Understand PowerShell string concatenation

    PowerShell uses the '+' operator to concatenate strings, not '*'.
  3. Final Answer:

    The '*' operator cannot be used for string concatenation in PowerShell. -> Option A
  4. Quick Check:

    Check operator usage in string concatenation [OK]
Quick Trick: Use '+' for string concatenation, not '*'. [OK]
Common Mistakes:
  • Using arithmetic operators like '*' or '-' for string concatenation.
  • Assuming variables need parentheses for concatenation.
  • Thinking Write-Output cannot display concatenated strings.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes