Under what circumstances can malloc return NULL?
问题 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 not work? I'm not talking about memory exhaustion : I'm looking for the simple case when you are allocating just one memory block in a bound size given by the user, lets say an integer, causes malloc to fail. 回答1: Yes. Just try to malloc more memory than your system can provide (either by exhausting your address space, or virtual memory -