title: Defining global variable in main()
body: <p>I want to define global array (used in other functions) based on input from <strong>main();</strong> (concretely array size). The <em>extern</em> keyword didn't help.</p>
  
  <pre><code>#include &lt;iostream&gt;
      using namespace std;
  
  void gen_sieve_primes(void);
  
  int main() {
      int MaxNum;
      cin &gt;&gt; MaxNum;
      int *primes = new int[MaxNum];
      delete[] primes;
      return 0;
  }
  //functions where variable MaxNum is used
  </code></pre>