Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Variables and Data Types
What will be the output of this PowerShell code?
$value = [int]'5.7'
Write-Output $value
A5.7
B5
CError
D6
Step-by-Step Solution
Solution:
  1. Step 1: Understand casting string '5.7' to int

    Casting string '5.7' to int truncates the decimal part, resulting in 5.
  2. Step 2: Check output of Write-Output

    It prints the integer 5, not 5.7 or 6, and no error occurs.
  3. Final Answer:

    5 -> Option B
  4. Quick Check:

    String to int truncates decimals = 5 [OK]
Quick Trick: Casting float string to int truncates decimals [OK]
Common Mistakes:
  • Expecting rounding instead of truncation
  • Thinking it throws an error
  • Assuming output stays as string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes