C++ for loop array assignment. Getting junk returned
<p>I'm trying to generate LIMIT (lets say limit = 1000) prime numbers and store them to an array, but I get junk returned. Here's my code:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
void prime_num(int);
int main()
{
    int primes[1000];
    int n, p, t, LIMIT = 1000;
    for(n=2; n &lt;= LIMIT; n++)
    {
        t=0;
        for(p=2; p &lt;= n/2; p++)
        {
            if (n%p == 0)
            {
                t = 1;
                break;
            }
        }
        if(!t) 
            primes[p-2] = n;
    }
    for (int i = 0; i &lt; LIMIT; i++)
        cout &lt;&lt; primes[i] &lt;&lt;" ";
    return 0;
}
</code></pre>
