#include <stdio.h>
#include <string.h>
void shiftArray(int arr[], int size, int m, int n) {
// 计算移动的字节数
size_t bytesToMove = (size - m) * sizeof(int);
// 将前m个元素往后移动n位
memmove(&arr[m + n], &arr[m], bytesToMove);
// 将移动后的位置填充为0或其他值
memset(&arr[m], 0, n * sizeof(int));
}
int main() {
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int size = sizeof(arr) / sizeof(arr[0]);
int m = 5; // 前m个元素
int n = 3; // 往后移n位
shiftArray(arr, size, m, n);
// 打印移动后的数组
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
【 在 daiyue 的大作中提到: 】
: 你去问chatgpt吧。以后这种级别的问题,不要来论坛问活人了。
: 问过一次chatgpt,你就会爱上它。
:
--
FROM 114.242.62.*