This involves allocating and de-allocating memory at run-time. Look into the new and delete operators for C++ or malloc and free for C.
Chat with our AI personalities
realloc - memory reallocator
it is initialised as follows:malloc/calloc/realloc will return NULL
Use the free function to release memory that was previously allocated by malloc, calloc or realloc.
As for pointers, I think you have to readjust them. Pointers are just variables that store a memory address in them. You can have as many pointers that point to a single location in memory as you want.
Realloc is a function in C. It is used to change the size of a block of memory by expanding it. There are various ways realloc can change the memory size, depending on if there is enough space in the block of memory.
/* Allocate space for an array with ten elements of type int. */int *ptr = malloc(10 * sizeof (int));if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */ realloc It is often useful to be able to grow or shrink a block of memory. This can be done using realloc which returns a pointer to a memory region of the specified size, which contains the same data as the old region pointed to by ptr (truncated to the minimum of the old and new sizes). If realloc is unable to resize the memory region in-place, it allocates new storage, copies the required data, and frees the old pointer. If this allocation fails, realloc maintains the original pointer unaltered, and returns the null pointer value. The newly allocated region of memory is uninitialized (its contents are not predictable). The function prototype is void *realloc(void *pointer, size_t size);