Bird
0
0

How can you display the result of adding two numbers stored in variables $a and $b in PowerShell?

hard📝 Application Q9 of 15
PowerShell - Basics and Environment
How can you display the result of adding two numbers stored in variables $a and $b in PowerShell?
A$a = 5; $b = 7; Write-Output "$a + $b"
B$a = 5; $b = 7; Write-Output '$a + $b'
C$a = 5; $b = 7; Write-Output ($a + $b)
D$a = 5; $b = 7; Write-Output $a $b
Step-by-Step Solution
Solution:
  1. Step 1: Assign numeric values to variables

    $a and $b are assigned numbers 5 and 7 respectively.
  2. Step 2: Use parentheses to calculate sum

    Using ($a + $b) inside Write-Output calculates the sum before output.
  3. Final Answer:

    $a = 5; $b = 7; Write-Output ($a + $b) -> Option C
  4. Quick Check:

    Parentheses evaluate expressions before output [OK]
Quick Trick: Use parentheses to calculate before output [OK]
Common Mistakes:
  • Outputting string of variables instead of sum
  • Missing parentheses for calculation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes