# Thread: copying values of an array to another array?!

1. ## copying values of an array to another array?!

Okay say i have a array a of 5 integers how do i copy the values to an array b?

here is a

Code:
`int a[5] = {5,4,3,2,1};`
what code could i write to copy that into another array b?...

2. A loop.

Or a recursive function. Or use memcpy(). But a loop is best.

3. of course it is! jeppers! im starting to worrie about my exams! lol!!!! i have the worst memory! lol! thanks for your help

4. okay.. heres my attempt.

Code:
```for (i=0;i<4;i++){
b[i] = a[i];
}```
im not sure about the b[i]=a[i] would that work? or do i need another variable for the array in a? any suggestions would be appreciated.

5. Edit: It should be i<5, because there are 5 elements in the array.

6. dose the array not start from 0 tho? or am i thinking of somthing completly different there?

7. i<4 is correct

8. It should be < 5 or <= 4, < 4 only copies the first 4 elements (0 - 3), while the array is (0 - 4).

9. In other words:
Code:
```int from[N] = {...}, to[N], x;

for(x = 0; x < N; x ++) {
to[x] = from[x];
}```