Practice question from FSharp Programming Advanced

What will this F# code produce? A. 8 B. 16 C. 24 D. 12 E. 6

let rec factorial n =
    match n with
    | 0 | 1 -> 1
    | _ -> n * factorial (n - 1)

printfn "%d" (factorial 4)

Answer

C

Explanation

The factorial of 4 is 4 * 3 * 2 * 1 = 24, which is the correct result of the recursive factorial function.

More questions from Quick: FSharp Programming Advanced