memcpy, . undefined.
memmove.
#include <stdio.h>
#include <string.h>
size_t remove_by_index( int a[], size_t n, size_t i )
{
if ( i < n )
{
memmove( a + i, a + i + 1, ( n - i - 1 ) * sizeof( *a ) );
--n;
}
return n;
}
int main( void )
{
int a[] = { 1, 10, 5, 8, 4, 51, 2 };
const size_t N = sizeof( a ) / sizeof( *a );
size_t n = N;
for ( size_t i = 0; i < n; i++ ) printf( "%d ", a[i] );
printf( "\n" );
n = remove_by_index( a, n, 1 );
for ( size_t i = 0; i < n; i++ ) printf( "%d ", a[i] );
printf( "\n" );
return 0;
}
1 10 5 8 4 51 2
1 5 8 4 51 2