title: Delete duplicates from array C++
body: <p>I am trying to create a simple program which calls on 2 functions. The first function takes a partially filled array, loops through it and deletes any duplicate values. When a value is deleted from the array, the remaining numbers are moved backwards to fill the gap i.e. when the function is finished, all null values of the array will be together at the end. </p>
  
  <p>The second function prints the updated array. </p>
  
  <p>My current code is below. At present when I run my code, the console shows: 
  2 6 0 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460. It should be showing: 1 2 5 6 if it worked correctly.</p>
  
  <p>Also, I am not sure how to move the remaining elements of the array backwards so that the null values will be together at the end.</p>
  
  <pre><code>#include "pch.h"
  #include &lt;iostream&gt;
  using namespace std;
  void deleteRepeats(int *arr, int arraySize, int&amp; posUsed);
  void printArray(int *arr, int arraySize);
  
  int main()
  {
  int arr[10] = { 1, 2, 2, 5, 6, 1};
  int posUsed = 6;
  int arraySize = 10;
  
  
  deleteRepeats(arr, arraySize, posUsed);
  printArray(arr, arraySize);
  
  return 0;
  }
  
  void deleteRepeats(int *arr, int arraySize, int&amp; posUsed)
  {
  {
      for (int i = 0; i &lt; arraySize; i++)
      {
          for (int j = i; j &lt; arraySize; j++)
          {
              if (arr[i] == arr[j])
              {
                  for (int k = j; k &lt; arraySize; k++)
                  {
                      arr[k] = arr[k + 1];
  
                  }
                  posUsed--;
  
              }
              else
                  j++;
          }
      }
  }
  }
  
  void printArray(int *arr, int arraySize)
  {
  for (int i = 0; i &lt; arraySize; i++)
  {
      cout &lt;&lt; arr[i] &lt;&lt; "  ";
  }
  }
  </code></pre>