在C語言中,你可以使用指針來合并兩個數組。以下是一種方法:
int arr1[] = {1, 2, 3, 4, 5};
int arr2[] = {6, 7, 8, 9, 10};
int *mergedArr;
int mergedArrLength = sizeof(arr1) / sizeof(arr1[0]) + sizeof(arr2) / sizeof(arr2[0]);
mergedArr = (int *)malloc(mergedArrLength * sizeof(int));
int i;
for(i = 0; i < sizeof(arr1)/sizeof(arr1[0]); i++){
mergedArr[i] = arr1[i];
}
for(i = 0; i < sizeof(arr2)/sizeof(arr2[0]); i++){
mergedArr[sizeof(arr1)/sizeof(arr1[0]) + i] = arr2[i];
}
for(i = 0; i < mergedArrLength; i++){
printf("%d ", mergedArr[i]);
}
free(mergedArr);
上述代碼會將兩個數組arr1和arr2合并成一個新的數組,并通過指針mergedArr來訪問合并后數組的元素。