Menu
Coddy logo textTech

Deletes Specific Index

Lesson 15 of 18 in Coddy's Functions in C++: Building Your Own Functions course.

challenge icon

Challenge

Easy

Write a function to delete an item from an array


write a function in C++ that takes an array and an index, and deletes the item at that specific index

Example:

  • If the array is {12, 34, 5, 67, 8}
  • And the index is 2
  • The output will be {12, 34, 67, 8}

If the index is not within the bounds of the array, print the message: "Invalid index!"

Try it yourself

#include <iostream>
#include <vector>
using namespace std;

void deleteElementAtIndex(vector<int> arr, int index) {
 
}

All lessons in Functions in C++: Building Your Own Functions