void * realloc(void*ptr , size_t size)
is the second argument supposed to be the number of bytes to be allocated, e.g
5 * sizeof(int)
or just the number of elements needed e.g
5 or 10
2 replies to this topic
#1
Posted 05 April 2011 - 01:13 AM
|
|
|
#2
Posted 05 April 2011 - 04:07 AM
Second argument is new size in bytes. If you want to add, lets say 4 more bytes, you'd call it something like this:
array = realloc(array, sizeOfArray + 4);
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#3
Posted 05 April 2011 - 07:18 PM
Yes, it tries to be a bit more flexible and allows you to enter your own terms of bytes, i.e. to double the size of an arbitrary array type
realloc( array, ( sizeOfArray * 2 ) * sizeof( array[0] ) );
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









