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
Just define it in global scope
int MaxNum;
int main(){
cin >> MaxNum;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With