Which allocation (Static / Dynamic) is suitable for the situation when
we are trying to allocate for a overloaded memory when the memory is
full and no space to allocate.
What will happen if both the allocation is impossible.
Sounds like a homework question to me...
But anyhow: The failure of dynamic allocation has well-defined
results: all of the dynamic allocation functions have methods
of indicating that they were unable to allocate more memory. This
allows you to cleanly detect and take action when memory is full.
Static memory has no defined method of indicating failure of
allocation, so you cannot cleanly detect and take action in
such cases.
If there is a failure of static memory allocation, then *some*
systems will generate a signal that can be handled through
the signal handling mechanism, but C89 at least does not define
a signal for this condition and does not document it as a
possibility, so any such signal would be an OS extension, not part of C
itself. And in C89, if the system itself raises any of the signals
defined specifically in C89, then behaviour of the program
after returning from the signal handler is undefined -- all of
the C89- defined signals are for conditions that are typically
fatal on most operating systems. (Note: if the program itself
used raise() to raise one of the C89- defined signals, then
returning from the signal handler -is- well defined.)
I would have to look up the details of the signals that C99 defines
to see if there are any of them for which returning from the signal
handler is well defined. C99 differs slightly from C89 in that
there are operations (such as overflow of a signed integer) that C89
just leaves the behaviour completely undefined, but for which C99
says that the behaviour is undefined or that the system may optionally
raise an implementation-defined signal. This is where the language
lawyers make their money, arguing about the difference between
behaviour that is -always- undefined, vs behaviour that the
implementation may define as being undefined!