title: C runtime error during recursive function call
body: <p>So I have a program to find the total number of ways in which an integer N can be expressed as the sum of "n" integers.
  For example, 10 can be expressed as a combination of 2,3 and 5 as follows-</p>
  
  <p>10 = 5 + 5</p>
  
  <p>10 = 5 + 3 + 2</p>
  
  <p>10 = 3 + 3 + 2 + 2</p>
  
  <p>10 = 2 + 2 + 2 + 2 + 2</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  int ways(int,int*,int);
  
  
  int main()    {
      int n,num; //n is number of possible integers 
      scanf("%d",&amp;n);
      int*curr=(int*)malloc(n*sizeof(int));     //dynamically allocated array that stores all "n" integers in array form
      for(int i=0;i&lt;n;i++)    {
          scanf("%d",curr+i); 
      }
      int t,N; //t is number of test cases
      scanf("%d",&amp;t);
      while(t--)    {
          scanf("%d",&amp;N);     //for each test case, scans the number N that needs to be expressed as a sum of combinations those "n" integers
          num=ways(N,curr,n);
          printf("%d\n",num);
      }
      return 0;
  }
  
  int ways(int N,int*p,int size) {
      int flag=1;
      for(int i=0;i&lt;size;i++) {
          if(N/(*(p+i))!=0)  {
              flag=0;
              break;
          }
  //Above loop says that if number N is less than all of the "n" integers, it 
  cannot be expressed as their sum. Hence, 0 will be returned if flag is 1
      }
      if(flag==1)
          return 0;
      if(N==0)
          return 1;
      int num=0,temp;
      for(int i=0;i&lt;size;i++) {
          temp=*(p+i);
          num=num+ways(N-temp,p,size);  //GETTING RUNTIME ERROR AT THIS LINE
      }   
      return num;
  }
  </code></pre>
  
  <p>The program is getting SIGSEGV error at the recursive function call even for very small depth of recursion</p>