answersLogoWhite

0

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.

User Avatar

Sonny Bernhard

Lvl 10
2y ago

What else can I help you with?

Continue Learning about Engineering

What if happen when you allocate memory by using malloc or calloc when the momory is not available contigiously?

malloc/calloc/realloc will return NULL


Which function should be used to free the memory allocated by calloc?

Use the free function to release memory that was previously allocated by malloc, calloc or realloc.


10 When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

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.


What is the use of realloc in c language?

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.


How can you increase the size of a statically allocated array?

/* 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);

Related Questions

What is the use of realloc in c program?

Increase or decrease the size of the allocated memory. (Note: functionality of malloc and free can be achieved with realloc, too.)


What is realloc memory allocation?

Use help/manual.


Is it legal to pass a null pointer as the first argument to realloc?

yes.


What is different between malloc and free?

malloc reserves memory for your use, free removes the reservation done by malloc and makes the memory available for other applications.Note: both of them is a special case of realloc:malloc (n) = realloc (NULL, n)free (p) = realloc (p, 0)


What are the different types of memory allocations in c?

1.malloc 2.calloc 3.realloc 4.free


What if happen when you allocate memory by using malloc or calloc when the momory is not available contigiously?

malloc/calloc/realloc will return NULL


Which function should be used to free the memory allocated by calloc?

Use the free function to release memory that was previously allocated by malloc, calloc or realloc.


10 When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

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.


What is the use of realloc in c language?

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.


How can you increase the size of a statically allocated array?

/* 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);


What function is used to release the memory on heap?

The free() function releases memory obtained with the malloc() family of functions. The delete and delete [] operators release memory obtained with the new operator. Note: realloc() can allocate and free memories as well as reallocate.


Memory allocation in c plus plus?

Although C++ inherits malloc/calloc, realloc and free from C, programmers are encouraged to use the object-oriented operators, new and delete instead. Not only are they much easier to use, they can also be used with primitive data types.