title: C++ Changing elements of an array using only pointers
body: <p>I'm working on a problem where I cannot use array indexing to change elements and I'm really struggling with pointers. This is code is supposed to initialize an array with all index initialized to 0, except for indexes 0 and 1. Indexes 0 and 1 are initialized to -1. The array I get back has weird numbers in it,</p>
  
  <pre><code>int* arr(int size);
  int main()
  {
      int low, high;
      char again = 'y';
      high = low = 0;
  
      cout &lt;&lt; "\tThe Sieve of Eratosthenes" &lt;&lt; endl &lt;&lt; endl;
      do
      {
          do
          {
              cout &lt;&lt; "Enter the high boundary: ";
              cin &gt;&gt; high;
              cout &lt;&lt; endl;
              if (high &lt;= 0)
                  cout &lt;&lt; "ERROR: HIGH BOUNDARY MUST BE POSITIVE" &lt;&lt; endl;
          } while (high &lt; 0);
  
          int* thearr = arr(high);
          cout &lt;&lt; "The prime numbers from to " &lt;&lt; high &lt;&lt; " are: " &lt;&lt; endl;
  
          for (int ix = 0; ix &lt;= high; ++ix)
          {
              cout &lt;&lt; thearr[ix] &lt;&lt; "  ";
          }
  
          cout &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; "Try again with new boundaries? (y/n):" &lt;&lt; endl;
          cin &gt;&gt; again;
  
          delete[] thearr;
  
      } while (again == 'y');
  
      return 0;
  }
  
  int* arr(int size)
  {
      int* thearray = new int[size];
      int last = size;
      cout &lt;&lt; *thearray &lt;&lt; " " &lt;&lt; last;
      while (*thearray &lt; last)
      {
          if (*thearray &lt;= 1)
              thearray[*thearray] = 0;
          else
              thearray[*thearray] = -1;
          ++thearray;
          cout &lt;&lt; *thearray;
      }
      return thearray;
  }
  </code></pre>