Copy array from certain position to another array in c

arrays, c++, for-loop, loops, memmove

I have array A and i want to copy this array from position x till y to another array in C language. Please help in creating it in c.

Using memcpy copies array from beginning only. I want to copy from particular position to another position.

Best Solution

int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };int b[5];memcpy( b, a + 5, 5 * sizeof( int ) );

Also you can do this using an ordinary for loop

for ( int i = 0; i < 5; i++ ) b[i] = a[i+5];