What is the dfference between realloc() and free()?
free() performs a task that is a subset of realloc(). Here's what realloc() does:
realloc(p, n): Changes the size of the block pointed to by p and returns p. If the size of that block cannot be changed, allocates a new block of n bytes, copies the contents of p, and then returns that new block.
realloc(NULL, n): Allocates a new block of n bytes and returns it. Functionally identical to malloc(n).
realloc(p, 0): Releases the memory allocated by p and returns NULL. Functionally identical to free(p).
If you're really interested, here's a sample implementation of realloc() and free(). That's a working implementation of stdlib.h, so you can also look at malloc() and the system-specific back end of each.
Just be aware that you should not use malloc(), realloc() or free() in c++ programs because they do not call c++ class constructors or destructors. Instead, use new and delete. Unfortunately there is no c++ equivalent of realloc().
free() is a macro which is used to deallocate memory.
free() is not a macro, it's a function.
When we need more memory realoc() reallocate memory according to given size.
While not technically wrong, there's so much missing that this answer borders on useless. It's essentually a tautology. You're saying that realloc() reallocates memory, which is obvious, redundant, and essentially defines realloc() in terms of itself.
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...