Q:

In the call to fact, why did we pass val - 1 rather than val--

0

In the call to fact, why did we pass val - 1 rather than val--?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The order of evaluation is undefined for the operator `*`, thus the expression `return factorial(val--) * val` make equal to either of the following expressions:

// Version 1
    auto tmp = factorial(val) * val;  // evaluate second operand first
    --val;
    return tmp;

    // Version 2
    auto tmp = factorial(val);
    --val;
    return tmp * val;  // evaluate first operand first

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now