Using malloc is giving me more memory than expected?

前端 未结 3 1799
甜味超标
甜味超标 2021-01-22 23:12

I\'m trying to get to grips with malloc, and so far I\'m mostly getting unexpected results when testing and playing around with it.

int main(int arg         


        
3条回答
  •  青春惊慌失措
    2021-01-22 23:36

    Undefined behavior doesn't mean "guaranteed segmentation fault"; it may work in some cases.

    There is no way of knowing how far beyond an array's bounds you can go before you finally crash; even dereferencing one element beyond a boundary is undefined behavior.

    Also: if malloc succeeds, it will allocate at least as much space as you requested, possibly more.

提交回复
热议问题