title: c++ how to add values to vector (or array) by function?
body: <p>I'll want to make a the Sieve of Eratosthenes, which I've made in the prime function, but the problem is that I'll want to use a vector, or something like it to store the value to later be use on the code, the rest is a binary search, but I don't know how to use the reference of the vector, I've done it on java, but the reference there is easy.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  int *primes (int size)
  {
      int* primArray = new int(size);
      int notPrime[size];
      for (int i = 0; i &lt; size; i++)
          notPrime[i]=0;
      int cont = 0;
      for(int i = 2; i &lt; size; i++)
      {
          if(notPrime[i] == 0)
          {
              primArray[cont] = i;
              cont++;
              int sum = i;
              for(int j = 1; sum &lt; size; j++)
              {
                  notPrime[sum] = 1;
                  sum = j*i;
              }
          }
      }
      return primArray;
  }
  </code></pre>
  
  <p>the problem up here</p>
  
  <pre><code>int search(int input, vector&lt;int&gt; array)
  {
      int min = 0;
      int max = array.size() - 1;
      int guess = (min + max)/2;
      int output = -1;
      while (true)
      {
          if (array[guess] == input)
          {
              output = guess;
              break;
          }
          if (min &gt; max)
          {
              output = -1;
              break;
          }
          if (array[guess] &lt; input)
              min = guess + 1;
          else
              max = guess - 1;
          guess = (min + max)/2;
      }
      return output;
  }
  
  int main()
  {
      scanf("%d", &amp;input);
      //int* array = primes(200);
      /*for (int i = 0; i &lt; 200; i++)
      {
          printf("%d, ", array[i]);
      }*/
      int numbers[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199};
      vector&lt;int&gt; primeArray (numbers, numbers + sizeof(numbers) / sizeof(*numbers));
      for (int i = 0; i &lt; primeArray.size(); i++)
      {
          printf("%d, ", primeArray[i]);
      }
      cout&lt;&lt; "\n";
      printf("%d", search(input, primeArray));
  }
  </code></pre>