C program to delete an element in an array: This program deletes or removes an element from an array. A user will enter the position at which the array element deletion is required. Deleting an element does not affect the size of the array. It also checks whether deletion is possible or not, for example, if an array contains five elements and user wants to delete the element at the sixth position, it isn't possible.
Remove element from array C program
int array, position, c, n;
printf("Enter number of elements in array\n");
printf("Enter %d elements\n", n);
for (c = 0; c < n; c++)
printf("Enter the location where you wish to delete element\n");
if (position >= n+1)
printf("Deletion not possible.\n");
for (c = position - 1; c < n - 1; c++)
array[c] = array[c+1];
for (c = 0; c < n - 1; c++)
C program to delete element from array output:
Download Delete element from array program.
You may have observed that we need to shift array elements which are after the element to be deleted, it's very inefficient if the size of the array is large or we need to remove elements from an array repeatedly. In linked list data structure shifting isn't required only pointers are adjusted. If frequent deletion is required and the number of elements is large, it's recommended to use a linked list.