title: Run time error for dynamic memory allocation in C++
body: <p>I am a newbie for OOP concepts and while trying to solve Project Euler <a href="https://projecteuler.net/problem=7" rel="nofollow">Problem 7</a>, to find 10001th prime number, I tried to do it using a class but encountered 2 major errors.</p>
  
  <ol>
  <li>instantiating the class <code>prime_n</code> </li>
  <li>initializing its argument</li>
  </ol>
  
  <p>I have posted the code here for reference:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstdio&gt;
  using namespace std;
  
  class prime_n
  {
       int j,k;
       int n;
       int *store;
  
       public:
       prime_n(int num)
       {
           n=num;
           store[n];
       }   
       static int isPrime(int j)
       {
            for(int i=2;i*i&lt;=j;i++)
            {
                 if(j%i==0) return 0;
            }
            return 1;
       }
       void find_n()
       {
            for(int i=0;i&lt;n;i++)
            {
                 store[i]=0;
            }
            store[0]=2;
            j=3;
            k=1;
            while(store[n-1]==0)
            {
                 if(isPrime(j)) store[k++]=j;
                 j+=2;
            }
       }
       int get_num()
       {
       int value=store[n-1];
       return value;
       }   
  };   
  
  int main()
  {
       int num, req_num;
       printf("Enter the position at which prime number is to be found ");
       scanf("%d",&amp;num);
       printf("\nnumber = %d",num);
  
       prime_n p = new prime_n(num);
  
       req_num = p.get_num();
       printf("The required prime number is %d\n",req_num);
       return 0;
  }
  </code></pre>
  
  <p>It would be a great help if someone could help me figure out where I am actually going wrong. Thanks a lot in advance!</p>