title: Why is the function prototype inside a different function block?
body: <p>I am trying to understand C, by going through K&amp;R. I have trouble understanding this code for two functions found in the book:</p>
  
  <pre><code>void qsort(int v[], int left, int right){
  int i, last;
  
  void swap(int v[], int i, int j);
  
  if (left &gt;= right)
      return;
  
  swap(v, left, (left+right)/2);
  
  last = left;
  
  for ( i = left+1; i&lt;=right; i++)
      if (v[i]&lt;v[left])
          swap(v,++last, i);
  
  swap(v,left,last);
  qsort(v,left,last-1);
  qsort(v,last+1,right);
  }
  
  
  void swap(int v[], int i, int j){
  
      int temp;
  
      temp = v[i];
      v[i] = v[j];
      v[j] = temp;
  }
  </code></pre>
  
  <p>These two function perform a quicksort on a given array. In the main function I created an int array and called qsort. It compiled fine and ran fine. My question is, why is the <strong>prototype</strong> for swap() put in the function qsort() and not before main()?</p>