I want to define global array (used in other functions) based on input from main(); (concretely array size). The extern keyword didn’t help.
#include <iostream>
using namespace std;
void gen_sieve_primes(void);
int main() {
int MaxNum;
cin >> MaxNum;
int *primes = new int[MaxNum];
delete[] primes;
return 0;
}
//functions where variable MaxNum is used
You declare it outside of main:
Ideally, you don’t do this at all. Globals are rarely useful, and hardly ever (or rather: never) needed.