The first approach is almost always better. Realloc () usually works by copying the entire contents of a block of memory into a larger block just allocated. Thus, n reallocs can mean n copies, each of which is larger than the last. (If you add m bytes to your distribution each time, then the first realloc should copy m bytes, next 2m, next 3m, ...).
The pedantic answer will be that the internal consequences of realloc () are implementation-specific, not specifically defined by the standard, in some implementations it can work as fairy fairies that instantly move bytes, etc. etc., but in any realistic implementation, realloc () means copy.
source share