69,371
社区成员
发帖
与我相关
我的任务
分享
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
size_t len = 3; //length of the array
int * a = calloc(len, sizeof(int));
for (int i = 0; i < len; i++)
{
a[i] = i + 1;
}
int pos = 1; //the pos of the element you want to delete
memmove(a + pos, a + pos + 1, len - pos - 1);
a = (int*)realloc(a, len - 1);
for (int i = 0; i < len - 1; i++)
{
printf("%d\n", a[i]);
}
}