What happens if I use malloc with the wrong size?

后端 未结 4 1763
[愿得一人]
[愿得一人] 2021-01-15 04:42

I\'m trying to learn more about memory allocation, and so I wrote some test code below to see what would happen if I tried to allocate memory of a less size than what I need

4条回答
  •  情书的邮戳
    2021-01-15 05:26

    it depends on the compiler and the os. On many, it eventually crashes. Definitely not recommended. Can potentially lead to buffer overflow as well.

提交回复
热议问题