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
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:
- Writing to a read-only portion of the memory.
- Accessing an array out of bounds.
- using a variable's value as an address.
- Dereferencing a null pointer.
- Dereferencing or assigning to an uninitialized pointer.
- 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
Computer Science,
1 month ago
Science,
2 months ago
Science,
9 months ago
Social Sciences,
9 months ago
Chemistry,
9 months ago