If there is no memory left on the heap malloc will return NULL.
Is the behaviour on stack overflow defined in C?
Wikipedia suggests it's likely to cause a segfault, at least in the case of infinite recursion, but could something else happen?
Also in many managed environments, the runtime does not allow you to create arrays on the stack. Does that mean we should avoid it in native code too to guard against stack overflow, at least when the size of the array is determined at run time?
malloc()can returnNULLif it's unable to allocate. That's the expected result if you run out of whatever memorymalloc()uses (we can choose to call that the "heap"). The point of this question is that there's nothing analogous for being unable to allocate memory for local variables in a function.