Skip to content

Commit

Permalink
删除函数delete中的搬移内存操作应该减多一个1
Browse files Browse the repository at this point in the history
如果不减多一个1,会将数组内存中未使用的第一个内存地址中的内容也复制到
已经使用的内存地址中。
  • Loading branch information
LittleFatHero authored Mar 24, 2019
1 parent ffc5da2 commit 60d597d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion c-cpp/05_array/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int delete(struct array *array, int idx)
return -1;

memmove(&array->arr[idx], &array->arr[idx+1],
(array->used - idx) * sizeof(int));
(array->used - idx - 1) * sizeof(int));
array->used--;
return 0;
}
Expand Down

0 comments on commit 60d597d

Please sign in to comment.