Bird
0
0

Identify the error in this PowerShell code:

medium📝 Debug Q14 of 15
PowerShell - Variables and Data Types
Identify the error in this PowerShell code:
$num = [int] 'abc'
ANo error, $num becomes 0
BSyntax error due to space between [int] and string
CRuntime error: Cannot convert 'abc' to int
DIt converts 'abc' to string automatically
Step-by-Step Solution
Solution:
  1. Step 1: Analyze casting 'abc' to int

    String 'abc' cannot be converted to integer, causing a runtime error.
  2. Step 2: Check syntax and error type

    Space between [int] and string is allowed; error is runtime conversion failure.
  3. Final Answer:

    Runtime error: Cannot convert 'abc' to int -> Option C
  4. Quick Check:

    Invalid string to int causes runtime error [OK]
Quick Trick: Invalid string to int causes runtime error [OK]
Common Mistakes:
  • Thinking space causes syntax error
  • Assuming it converts to zero
  • Believing it auto-converts to string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes