use unintialized_copy where is initialized

S

Stanley Rice

`the difference between *uninitialized_copy* function and *copy* is that the
*uninitialized_copy* function could copy the object at the location where
is uninitialized. For example:

int ia[5] = {1, 2, 3, 4, 5};
int n = sizeof ia / sizeof *ia;
int *ib = (int *)malloc(n * sizeof *ia);
uninitialized_copy(ia, ia + n, ib);

My question is, what if I copy the initialized memory by calling the
uninitialized_copy function. Instead of allocatiing the memory by calling
malloc, I use new.
int *ib = new int[n];
uninitialized_copy(ia, ia + n, ib);

I works too. But am i correct? If so, what's the difference between copy
and uninitialized_copy?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top