Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Surely it always succeeds?

succeeds SURELY
0
10 Posted

Surely it always succeeds?

0

For small programs, and during light testing, it is true that malloc usually succeeds. Unfortunately, there are all sorts of unpredictable reasons why malloc might fail one day; for example: • Someone uses your program for a far larger data set than you anticipated; • Your program is running on a machine with less memory than you expected; • The machine your program is running on is heavily loaded. In this case, malloc will return NULL, and your program will attempt to store data by resolving the null pointer. This might cause your program to exit immediately with a helpful message, but it is more likely to provoke mysterious problems later on. If you want your code to be robust, and to stand the test of time, you must check all error or status codes that may be returned by functions you call, especially those in other libraries, such as the C run-time library.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123