Home » C++ Programming » Comments » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    long fact (long p)
    {
    if (p > 1)
    return (p * fact (p + 1));
    else
    return (1);
    }
    int main ()
    {
    long n = 6;
    cout << n << "! = " << fact ( n );
    return 0;
    }

    1. 1
    2. 6
    3. segmentation fault
    4. compile time error
    5. None of these
Correct Option: C

As we have given in the function as p+1, it will exceed the size and so it arises the segmentation fault.



Your comments will be displayed only after manual approval.