Bird
0
0

Find the problem in this function:

medium📝 Debug Q7 of 15
PowerShell - Functions
Find the problem in this function:
function AddNumbers { param([int]$a = 1, [int]$b) $a + $b }

What happens if you call AddNumbers without arguments?
AError because parameter 'b' has no default and is missing
BReturns 1 because 'a' defaults to 1 and 'b' is null
CReturns 0 because both parameters default to 0
DReturns sum of 1 and 0
Step-by-Step Solution
Solution:
  1. Step 1: Check parameters and defaults

    Parameter 'a' has default 1; 'b' has no default.
  2. Step 2: Call function without arguments

    Missing 'b' causes error because it is required.
  3. Final Answer:

    Error because parameter 'b' has no default and is missing -> Option A
  4. Quick Check:

    Required params missing cause error [OK]
Quick Trick: All non-default params must be passed or error occurs [OK]
Common Mistakes:
  • Assuming missing non-default param becomes null
  • Expecting default 0 for int without default
  • Ignoring required parameter rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes