Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q4 of 15
PowerShell - Variables and Data Types
What will be the output of this PowerShell code?
$city = "Boston"
$temperature = 75
Write-Output "The temperature in $city is $temperature degrees"
AThe temperature in $city is 75 degrees
BThe temperature in $city is $temperature degrees
CThe temperature in Boston is $temperature degrees
DThe temperature in Boston is 75 degrees
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable substitution

    Within double quotes, PowerShell replaces variables with their values.
  2. Step 2: Analyze the code

    $city is "Boston" and $temperature is 75, so the string becomes "The temperature in Boston is 75 degrees".
  3. Final Answer:

    The temperature in Boston is 75 degrees -> Option D
  4. Quick Check:

    Variables inside double quotes get expanded [OK]
Quick Trick: Variables expand inside double quotes [OK]
Common Mistakes:
  • Expecting variables not to expand inside double quotes
  • Confusing variable names with literal strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes