0

When i run this code, it breaks

main(){
   long a[1000][1000];
}

but when i change to this,

long a[1000][1000];
main(){}

it runs well.

I assumed that there is the memory limit inside-function variables, am i right ?

If so, what is the memory limit (in bytes) for those ?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Era
  • 1
  • 1
  • 1
    Stacks has a limit on its size, and depends on OS and compiler. Thats why your first snippet broke – Amadeus Oct 23 '17 at 03:31
  • Useful reading: http://en.cppreference.com/w/cpp/language/storage_duration. Particularly the piece on Automatic Storage Location (Also Known As most "inside-function variables"). – user4581301 Oct 23 '17 at 04:32

1 Answers1

1

The exact limit is compiler and platform specific.

The difference is in the two snippets is that the first example allocates memory from the stack, while the second allocates it statically - before the program starts. The stack generally is smaller.

AShelly
  • 34,686
  • 15
  • 91
  • 152