0

Array shift

If I want to delete array element by shifting to left from some index, does it matter if I happen to reference past array bounds? Like, when deleting last element. Heres what I mean: if (nelem > index) { nelem--; memcpy(&data[index], &data[index + 1], sizeof (MyData) * (nelem - index)); }

23rd Mar 2020, 5:43 PM
Daniel
Daniel - avatar
4 Antworten
+ 1
Thanks!
23rd Mar 2020, 6:10 PM
Daniel
Daniel - avatar
0
Hmm, wait, how about if I check if element to be removed is last one and then just decrease element count? Otherwise do as in 1st post.
23rd Mar 2020, 6:03 PM
Daniel
Daniel - avatar