Bird
0
0

Why does the expression '$a / $b' in PowerShell sometimes return a decimal and sometimes an integer?

hard📝 Conceptual Q10 of 15
PowerShell - Operators
Why does the expression '$a / $b' in PowerShell sometimes return a decimal and sometimes an integer?
ABecause PowerShell automatically converts to floating point if needed
BBecause division operator returns only integers
CBecause variables must be declared as integers explicitly
DBecause PowerShell does not support division
Step-by-Step Solution
Solution:
  1. Step 1: Understand PowerShell division behavior

    PowerShell returns a floating-point number if division is not exact.
  2. Step 2: Recognize automatic type conversion

    PowerShell converts to decimal automatically when needed.
  3. Final Answer:

    Because PowerShell automatically converts to floating point if needed -> Option A
  4. Quick Check:

    Division returns float or int based on values [OK]
Quick Trick: Division returns float if remainder exists, else integer [OK]
Common Mistakes:
  • Thinking division returns only integers
  • Believing explicit int declaration needed
  • Assuming division unsupported

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes