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

Recommended Answers

All 2 Replies

It is the size (in bytes) of the memory you want to request. In general, you determine this with the sizeof operator as with your first example.

or just the number of elements needed

What size is each element? Since void doesn't have a size, there's no way to tell without a parameter specifying the element size (calloc, for example). realloc has no such parameter, so by deduction we can conclude that the second parameter refers to the total number of bytes being requested (just like malloc), not the number of elements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.