Bird
0
0

Identify the error in this PowerShell code:

medium📝 Debug Q6 of 15
PowerShell - Variables and Data Types
Identify the error in this PowerShell code:
$num = [int]3.7
Write-Output $num
ASyntax error due to casting float to int
BNo error; $num will be 3
CRuntime error: cannot convert 3.7 to int
DOutput will be 4 due to rounding
Step-by-Step Solution
Solution:
  1. Step 1: Understand casting float to int in PowerShell

    PowerShell truncates decimals when casting float to int, no error occurs.
  2. Step 2: Predict output value

    3.7 cast to [int] becomes 3 by truncation.
  3. Final Answer:

    No error; $num will be 3 -> Option B
  4. Quick Check:

    Float to int truncates without error [OK]
Quick Trick: Casting float to int truncates decimals, no error [OK]
Common Mistakes:
  • Expecting rounding instead of truncation
  • Thinking casting causes error
  • Confusing syntax with runtime error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes