Under what circumstances can malloc return NULL?

前端 未结 9 1612
陌清茗
陌清茗 2020-12-23 14:17

It has never happened to me, and I\'ve programming for years now.

Can someone give me an example of a non-trivial program in which malloc will actually

9条回答
  •  礼貌的吻别
    2020-12-23 14:59

    Just check the manual page of malloc.

    On success, a pointer to the memory block allocated by the function.
    The type of this pointer is always void*, which can be cast to the desired type of data pointer in order to be dereferenceable.
    If the function failed to allocate the requested block of memory, a null pointer is returned.

提交回复
热议问题