This code gives runtime error.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxc = 1e6+10;
ll bit[maxc];
ll n;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll a[maxc] , u[maxc] , q[maxc];
//some stuff with the arrays
return 0;
}
And this works fine.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxc = 1e6+10;
ll bit[maxc];
ll a[maxc] , u[maxc] , q[maxc];
ll n;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//some stuff with the arrays
return 0;
}
Can anyone tell me why??
Can you post a link to your submissions please?
Also, which question are you solving?
It's a stack overflow problem — literally.
The first code tries to allocate the arrays in the stack while the second one allocate them in the heap.
You can try to compile the first code with the --stack=268435456 parameter (the same that CF uses).
Because When You declare Array Global it will be in Stack So It will have larger Capacity of elements.
If you declare it in Main it will be in Heap So It will have lower Capacity of Elements and will give Runtime Error.
You have the naming completely mixed up. Global variables have static storage duration and are neither in stack or heap. Variables in function are in stack not heap.
Yes , I think I mixed up between Them