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.
The realloc() function in the C run-time library changes the allocation of a previously allocated memory block. If the new allocation is shorter than the old allocation, the end of the allocated memory is deleted. If the new allocation is longer than the old allocation, the old allocation is copied to the new allocation, and the new portion of the allocation is undefined.
char* pchar = (char*) malloc(100); /*allocate 100 bytes */
pchar = (char*) realloc (pchar, 200); /* change allocation to 200 bytes */
However, and this is important to proper program design...
You should always check the result of malloc() to see if it returned NULL, which means that it failed to find enough memory.
The same thing goes for realloc() and, additionally, the example above can cause a memory leak. This is because if realloc() failed, pchar is set to NULL, losing the address of the previously "successful" allocation, because you never called free().
A proper example...
char* pchar;
char* pchartemp;
if ((pchar = (char*) malloc (100)) NULL) {
... report realloc() failure and abort ...
} else {
pchar = pchartemp;
}
... use larger pchar ...
free (pchar);
The realloc() function modifies a memory location previously allocated using malloc(). The prototype is void * realloc(void *ptr, size_t size);
First argument ptr is a pointer to the previously allocated memory and the second is the new size in bytes.
The function returns ptr if sufficient space is available to expand the memory block. If sufficient space does not exist to expand the current block in its current location, a new block of the size is allocated, and existing data is copied from the old to the new block. The old block is freed, and a pointer to the new block is returned.
If argument ptr is NULL, the function acts like malloc(), allocating a block of size bytes and returning a pointer to it.
If argument size is 0, the memory that ptr points to is freed, and the function returns NULL.
If memory is insufficient for reallocation, the function returns NULL and the original block remains unchanged.
There is no part called 'loader' in C language.
c++
Bitwise OR.
thread is not specific to C-language. Use wikipedia to find out what threads are, and use Posix Threads (or pthreadsfor short) to create multi-threaded programs in C
Yes.
Increase or decrease the size of the allocated memory. (Note: functionality of malloc and free can be achieved with realloc, too.)
Use help/manual.
I do use am a programmer, because C-language.
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.
There is no part called 'loader' in C language.
1.malloc 2.calloc 3.realloc 4.free
TO use a c language first step is to know about the c language and the steps to use the c progrmming language with the help of any elders or with the teachers. TO use the arrays you have to get th eknowledge of "c" language
To run C language?! Your question makes no sense.
C has nothing to do with graphics.
No, it is a programming language.
Programming, mainly.
In computer-programming.