Bird
0
0

Find the error in this PowerShell snippet:

medium📝 Debug Q7 of 15
PowerShell - Variables and Data Types
Find the error in this PowerShell snippet:
$val = [float]'abc'
ARuntime error: cannot convert string 'abc' to float
BNo error; $val becomes 0
CSyntax error due to invalid cast
DOutput is string 'abc' stored as float
Step-by-Step Solution
Solution:
  1. Step 1: Analyze casting string to float

    PowerShell cannot convert non-numeric string 'abc' to [float], causing runtime error.
  2. Step 2: Confirm error type

    This is a runtime conversion error, not syntax error.
  3. Final Answer:

    Runtime error: cannot convert string 'abc' to float -> Option A
  4. Quick Check:

    Invalid string to float cast causes runtime error [OK]
Quick Trick: Casting non-numeric string to float causes runtime error [OK]
Common Mistakes:
  • Expecting silent conversion to 0
  • Thinking it's a syntax error
  • Assuming string stored as float

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes