Module 1 · Arrays · Common Mistakes

Arrays: common mistakes

Shifting values in an array looks simple, and that's where values get lost. Here are three slips in MyArray's insert and remove: shifting right from the front, a shift loop that reads past the last slot, and forgetting size--. Dimmed cells are past size.

Pick a mistake and press play: Wrong runs the code with the mistake until it breaks, and the code marks the wrong line in red. Fixed runs the corrected code on the same input, with the corrected line in green.

Mistake
Code