+ 19
I am not able to understand how thies code m[i-1]=m[i];is 👉 deleting an element from an array useing for loop?
can some one explain me thies 👆 https://code.sololearn.com/cTuPAI8J7bTj/?ref=app
3 odpowiedzi
+ 4
imagine you want to remove 3rd element from this array
{1, 2, 3, 4, 5}
inorder to remove 3rd element, we need to shift 4th, 5th left once
result would be
{1, 2, 4, 5}
m[i-1] = m[i] does this job for you i.e it shifts [i]th element to the [i-1]'s place
+ 3
in line 19 u are assigning m[2]=m[3] that's why it delete the m[2] and then. n-- make n=4