WHY does this happen???

I have seen this happening with my codes a lot but cant figure out the reason…why does this code run and this give RE???

2 Likes

global variable store in HEAP and On heap The size limit here is a combination of available hardware and the OS’s ability to simulate space by using other devices to temporarily store unused data.

and local variable store in stack and On the stack The size limit here is compiler defined (with possible hardware limits). If you read the compiler documentation you can often tweak this size. Thus if you allocate an array dynamically or take as global variable (the limit is large ).

8 Likes

When the variable are declared locally they are stored in stack as chandran11111 said.More over the global variables size limit is extended wen compared to local variables.Another fact about global variables is that the default value is 0 where as in the case of local variables it is garbage…:slight_smile:
Nice question…:slight_smile: