Computer Science, asked by amishajain18, 4 months ago

What is the output of this program?
using namespace std;
long factorial (long a)
{
if (a > 1)
return (a * factorial (a + 1));
else
return (1);
}
int main ()
{
long num = 3,
cout << num << "!="<< factorial ( num ).
return 0;
}​

Answers

Answered by dreamrob
0

Answer:

We will not get any output.

Error: Segmentation fault

Segmentation fault: a memory access violation caused by a program attempting an illegal memory location.

Causes:

  1. Writing to a read-only portion of the memory.
  2. Accessing an array out of bounds.
  3. using a variable's value as an address.
  4. Dereferencing a null pointer.
  5. Dereferencing or assigning to an uninitialized pointer.
  6. Dereferencing or assigning to a freed pointer.

Correct program for factorial:

#include<iostream>

using namespace std;

long factorial (long a)

{

if (a > 1)

{

             return (a * factorial (a - 1));  

}

else

{

             return (1);

}

}

int main ()

{

     long num = 3;

     cout << num << "!="<< factorial ( num );

     return 0;

}

Similar questions