Simple pointer question (:)

J

J

Hi,

I have an array:

double *array = new double[50];


Well, I have 2 actually.


double *array2 = new double[50];


Say 'array' is poulated with 'doubles'. How do I copy all of array's values
into 'array2'?




TIA,
-- JA
 
T

Thomas Wintschel

J said:
Hi,

I have an array:

double *array = new double[50];


Well, I have 2 actually.


double *array2 = new double[50];


Say 'array' is poulated with 'doubles'. How do I copy all of array's values
into 'array2'?




TIA,
-- JA

memcpy(array2, array, 50 * sizeof(double));
 
J

J

Thanks my friend, totally forgot memcpy. (Haven't programmed in awhile!!)


- JA


J said:
Hi,

I have an array:

double *array = new double[50];


Well, I have 2 actually.


double *array2 = new double[50];


Say 'array' is poulated with 'doubles'. How do I copy all of array's values
into 'array2'?




TIA,
-- JA

memcpy(array2, array, 50 * sizeof(double));
 
M

Mike Wahler

J said:
Hi,

I have an array:

double *array = new double[50];


Well, I have 2 actually.


double *array2 = new double[50];


Say 'array' is poulated with 'doubles'. How do I copy all of array's values
into 'array2'?

std::copy(array, array + 50, array2);

This assumes that 'array' and 'array2' each have at least
50 elements, and that all elements of 'array' have valid
values.

'std::copy()' is declared by <algorithm>.

-Mike
 
R

Roy Varghese

Thomas said:
Hi,

I have an array:

double *array = new double[50];


Well, I have 2 actually.


double *array2 = new double[50];


Say 'array' is poulated with 'doubles'. How do I copy all of array's
values

into 'array2'?
memcpy(array2, array, 50 * sizeof(double));
Hmm...whats memcpy doing in a c++ forum :)
 
M

Mike Wahler

Roy Varghese said:
Thomas said:
Hi,

I have an array:

double *array = new double[50];


Well, I have 2 actually.


double *array2 = new double[50];


Say 'array' is poulated with 'doubles'. How do I copy all of array's
values

into 'array2'?
memcpy(array2, array, 50 * sizeof(double));
Hmm...whats memcpy doing in a c++ forum :)

memcpy() is a standard C++ library function.

-Mike
 

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

No members online now.

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top