title: Swapping function c
body: <p>I have to write a swap function for my bubble sort<br>
  That's what I've got:</p>
  
  <pre><code>void swap(int arr[], int size, int i, int j)
  {
      int temp = *(arr+i);
      *(arr + i) = *(arr+j);
      *(arr+j) = temp;
  }
  </code></pre>
  
  <p>When I'm trying to run I get the following errors:</p>
  
  <blockquote>
    <p>warning C4013: 'swap' undefined; assuming extern returning int
    error C2371: 'swap' : redefinition; different basic types</p>
  </blockquote>
  
  <p>When I do change the function to the type of <code>int</code>, it does work, any idea why?</p>
  
  <p>I don't need a prototype because it's before the main function... do I?</p>
  
  <p>Here's the whole code:</p>
  
  <pre><code>//BubbleSort
  
      void bubbleSort(int arr[], int size)
      {
          int i,j;
          for(i=0; i &lt; size; i++)
          {
              for(j=i+1; j &lt; size; j++)
              {
                  if(*(arr+i) &gt; *(arr+j))
                  {
                       /*temp = *(arr+i);
                      *(arr + i) = *(arr + j);
                      *(arr + j) = temp;*/
                      swap(arr,i,j);
                  }
              }
          }
      }
      void swap(int arr[], int i, int j)
      {
          int temp = *(arr+i);
          *(arr + i) = *(arr+j);
          *(arr+j) = temp;
      }
      void main()
      {
          int i, arr[] = {8,0,6,-22,9};
          bubbleSort(arr, sizeof(arr)/sizeof(int));
          for(i=0; i &lt; sizeof(arr)/sizeof(int); i++)
          {
              printf("%d, ",*(arr+i));
          }
          printf("\n");
      }
  </code></pre>