--- In [email protected], andrew clarke <[EMAIL PROTECTED]> wrote:
>
> > Array copying is done in line number 12. Is this allowed in C++? I did
>
> Since both arrays are the same size you can use memcpy:
> 
> memcpy(same_age, age, sizeof same_age);
> 
> Or just write a loop:
> 
> for (i = 0; i < 4; i++)
> {
>     same_age[i] = age[i];
> }

If you have arrays of the same size which logically represent the same
information eg. "an array of ages", in C I would define a structure
type just containing the array and used that instead - structures can
be assigned. This is safer than memcpy because you don't need to
include a 'size' (which you could get wrong):

(NB. C code)

typedef struct
{
    int a[4];
} Ages;

    Ages age, same_age;
    :
    age.a[0] = 23;
    :
    same_age = age;

Presumably you can do the same or similar in C++.

John

Reply via email to