realloc is used to reallocate the memory dynamically.
Suppose I have allocated 7 bytes using the malloc function and now I want to extend it to 30 bytes.
What will happen in the background if there is no sequential (continously in a single row) space of 30 bytes in the memory?
Is there any error or will memory be allocated in parts?
reallocworks behind the scenes roughly like this:NULL.So, you can test for failure by testing for
NULL, but be aware that you don’t overwrite the old pointer too early: