title: calling function inside another function (but not recursion)
body: <p><strong>I have written a code for merge sort in C, but when I call function merge() within mergesort(), compilers shows error. Any reasons why so?</strong>
  <strong><em>I am trying to write mergesort algorithm</em></strong>
  There's no more details I have written it for the damned condition of stack overflow.</p>
  
  <pre><code>            #include&lt;stdio.h&gt;
              #include&lt;stdlib.h&gt;
              int mergesort(int* A,int n)
              {
                  if(n==1)
                     return 0;
                  int ln,rn;//to calculate length of left and right arrays
                  int *L,*R;//pointer to left and right arrays
                  L=(int*)malloc(ln*sizeof(int));
                  R=(int*)malloc(rn*sizeof(int));
                  ln=n/2;
                  rn=n-ln;
                  for(int i=0;i&lt;ln;i++)
                  {
                      L[i]=A[i];
                  }   
                  for(int i=0;i&lt;rn;i++)
                  {
                      L[i]=A[i+rn];
                  }
                  mergesort(L,ln);
                  mergesort(R,rn);
                  merge(A,L,R,n,ln,rn);
                  return 0;
              }
              int merge(int*A,int*L,int*R,int n,int ln,int rn)
              {
                  int i,j,k;//to access elements of A,L,R respectively
                  i=j=k=0;
                  while(j&lt;ln&amp;&amp;k&lt;rn)
                  {
                      if(L[j]&lt;=R[k])
                      {
                          A[i]=L[j];
                          i++;
                          j++;
                      }
                      else
                      {
                          A[i]=L[k];
                          i++;
                          k++;    
                      }
                  }
                  while(j&lt;ln)//means R is fully copied to A,but not L
                  {
                          A[i]=L[j];
                          i++;
                          j++;    
                  }
                  while(k&lt;ln)//means L is fully copied to A,but not R
                  {
                          A[i]=L[k];
                          i++;
                          k++;    
                  }
                  return 0;
              }
              int main()
              {
                  int* A,i,n;
                  //scanf("array size: %d",&amp;n);//dunno it's valid or not
                  scanf("%d",&amp;n);
                  A=(int*)malloc(n*sizeof(int));
                  printf("\n");
                  for(i=0;i&lt;n;i++)
                  {
                      scanf("%d",&amp;A[i]);
                  }
                  mergesort(A,n);
                  for(i=0;i&lt;n;i++)
                  {
                      printf("%d ",A[i]);
                  }
                  return 0;
              }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/xvHZt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xvHZt.png" alt="enter image description here"></a></p>