When you compile programs, particularly when learning, you should turn on warnings to help you diagnose problems. If you had you would probably get a warning about the following line of code
for(int i=0; i<10000000000; i++)
for which I get the warning that the comparison
i < 10000000000
is always true due to the range of i. So that would be one clue.
Further to what CPalini has said in Solution 1, the reason you are getting a core dump is that you've asked for the 80 GB on the
stack
not on the heap (i.e. using
malloc()
). On Windows the maximum stack size is usually about 1 MB, whereas on Linux the default stack size is 8MB. So even though the program compiles, when you try to run it, it runs into a stack size violation and terminates. If you were to use
malloc()
to try to allocate memory to your program it might work - as long as you're on a 64-bit OS. A 32 Bit OS can only allocate 4 GB per process. Even if you're on a 64-bit system, malloc might return a good value for an 80GB data segment, but you still might get a program crash when trying to access all data elements, unless you have at least 80GB of RAM+swap - which even today is rare for a user workstation.