Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q4 of 15
PowerShell - Control Flow
What will be the output of this PowerShell code?
switch -Wildcard ('cat', 'car', 'dog') {
  'ca*' { 'Starts with ca' }
  'd*' { 'Starts with d' }
  default { 'No match' }
}
AStarts with ca No match Starts with d
BStarts with ca Starts with ca
CStarts with ca Starts with ca Starts with d
DNo match No match No match
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate each input against wildcard patterns

    'cat' matches 'ca*' so outputs 'Starts with ca'. 'car' also matches 'ca*' so outputs 'Starts with ca'. 'dog' matches 'd*' so outputs 'Starts with d'.
  2. Step 2: Confirm default case is not triggered

    All inputs match one of the patterns, so default is not used.
  3. Final Answer:

    Starts with ca Starts with ca Starts with d -> Option C
  4. Quick Check:

    Wildcard matching outputs all matches [OK]
Quick Trick: Each input can match multiple cases unless break used [OK]
Common Mistakes:
  • Assuming only first match prints
  • Ignoring that 'car' matches 'ca*'
  • Thinking default runs for matched inputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes