Edit
Now I want to know if it is possible to make ar
as a global variable supposing I'm using g++
.
My confusion comes from This answer.
Consider the following code:
#include <iostream>
int main() {
int N;
std::cin >> N;
int ar[N] ={0};
for(int i=0; i<N; i++) {
std::cout << ar[i] << '\n';
}
return 0;
}
This code works perfectly fine. so why saying that we can't do this?
Besides, the real problem I want to solve is how can I make ar
global?
#include <iostream>
int N;
int main() {
std::cin >> N;
int ar[N] ={0};
for(int i=0; i<N; i++) {
std::cout << ar[i] << '\n';
}
return 0;
}
The above code only set N
to global, but if I want to make ar
global, I don't know how to do