title: Segmentation fault (core dumped) with sieve algorithm
body: <p>I've been trying to implement the sieve algorithm using the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main() {
      vector &lt;int&gt; primes; //all the primes found
      int theLimit = 10E5;
  
      void sieve (vector &lt;int&gt; &amp;primes, int theLimit); //declaring the function
      sieve (primes, theLimit);
  
      return 0;
  }
  
  void sieve (vector &lt;int&gt; &amp;primes, int theLimit) {
      const int SIZE = theLimit + 1;
      bool oddNonPrimes[SIZE]; //the array that tells you that tells you if the number that represents the current index is a non-prime or not
  
      for (int i = 0; i &lt; theLimit; ++i) //setting all the array indicies to false
          oddNonPrimes[i] = false;
  
      primes.push_back(2);
  
      for (int i = 3; i &lt; theLimit; i += 2){ //start searching for primes,we start with the number 3 and check all odd numbers only
          if (!oddNonPrimes[i]){
               int currNum = i;
               primes.push_back(currNum);
               for (int factor = 2; currNum &lt;= theLimit; ++factor){
                  currNum *= factor;
                  oddNonPrimes[currNum] = true;
                  currNum = i;
              }
          }
      }
  
  }
  </code></pre>
  
  <p>I've tried lowering the size to make sure I'm not using too much memory but it still didn't work.I've also tried searching for an answer but I haven't found any.</p>
  
  <p>What could be causing the Seg fault?and why?</p>