So,i was solving a problem on SPOJ.I have to handle large number of values of order 2^18.I am on a system with 4 GB ( 2**34 Bytes) ram. While allocating memory for my program , i observed something strange. I am using long long qualifier for storing the input in two arrays sum1[1<<17] and sum2[1<<17].So, total memory allocated by the two arrays is 2^17*8 + 2^17*8 = 2^21 Bytes.The part of code i want to refer is :
#include <stdio.h>
int main()
{
    // some code 
    int a=17,b=17;
    long long sum1[1<<a], sum2[1<<b]; 
    // some more code 
}
The problem is that whenever a+b >= 34 , the program stops working, else it works fine.I guess it is due to unavailability of large space. But if i make the two arrays global like that :
#include <stdio.h>
long long sum1[1<<18], sum2[1<<18]; 
int main()
{
    // some code 
}
It works great and doesn't bother about a+b <= 34 , as you can see it works fine for 1<<18.So what's happening under the hood.
Regards.
 
     
    