Question: My code for finding reverse by recursion says **Segmentation Fault**
Why?And how to find reverse by recursion?
What is wrong with my code?

```
 #include<stdio.h>
int rev(int);
main()
{
    int a,b;
    scanf("%d",&a);
    b=rev(a);
    printf("%d",b);
}
int rev(int x)
{
    int q,r;
    static int p=0;
    p=p*10+(x%10);
    r=x/10;
   q=rev(r);
    return(p);
}

```

Answer: 
A recursive function needs a way to know when the recursion ends. This is referred to as the **base case**. Without a base case, the recursion will keep happening until you run out of stack space, which typically causes your program to crash.

For your code, you want to get out when the argument is 0. So you need to to this:

```
int rev(int x)
{
    int q,r;
    static int p=0;
    if (x == 0) return;    // base case
    p=p*10+(x%10);
    r=x/10;
    q=rev(r);
    return(p);
}

```
Add any breaking condition in your code in you rev() function

```
if x == 0:
       return 0

```