Why doesn't my program crash when I write past the end of an array?

前端 未结 9 1241
-上瘾入骨i
-上瘾入骨i 2020-11-22 12:47

Why does the code below work without any crash @ runtime ?

And also the size is completely dependent on machine/platform/compiler!!. I can even give upto 200 in a 64

9条回答
  •  无人共我
    2020-11-22 12:47

    That's undefined behavior - you simply don't observe any problems. The most likely reason is you overwrite an area of memory the program behavior doesn't depend on earlier - that memory is technically writable (stack size is about 1 megabyte in size in most cases) and you see no error indication. You shouldn't rely on this.

提交回复
热议问题