The function deletes the desired element from the array by index.
bool del(int *arr, int &length, int index) { if (index < 0 || index > length) return false; for (int i = index; i<length; i++) { arr[i] = arr[i+1]; } length--; return true; } Question: let's say there is an array arr [3] = {1,2,3} and you need to delete the element under the index 2 (element equal to 3)
Then the following code will be launched in the function:
arr[2] = arr[3] and what is stored in this arr [3]? The program does not swear at this and adequately removes the index I need, and as a result, the array {1,2} is obtained