Suppose pp is a pointer to an array of structs of length n. [was dynamically allocated] Suppose I want to create a copy of that array of structs and make a pointer to it, the following way:
struct someStruct* pp2 = malloc(_appropriate_size_);
memcpy(pp2, pp, _appropriate_length_);
I also can make a loop and do pp2[i]=pp[i]
for 0 <= i <= n
.
What is the difference between these approaches, and which is better and why?