0
使用memcpy(),我想複製部分數組到另一個源數組是雙指針數組的地方。是否有解決方案來實現這樣的複製過程沒有更改雙指針?兩個不同指針之間的memcpy()
int **p;
p= malloc(sizeof(int *));
p= malloc(5 * sizeof(int));
int *arr;
arr= malloc(5 * sizeof(int));
for(i = 0; i < 5; i++){
p[i] = 1;
}
memcpy(arr, (2+p) , 3*sizeof(int)); // I want to start copying 3 elements starting from the third position of the src.
你不分配內存以'arr'。 – ameyCU
對不起,這是一個錯誤。我的意思是arr –
'p = malloc(sizeof(int *)); p = malloc(5 * sizeof(int));' - 這看起來不正確... –