C Programming
- Print integer
- Add & subtract
- Odd & even
- Multiply & divide
- Check vowels
- Letter grade program
- Leap year program
- Sum of digits
- Prime numbers
- Sum of numbers
- Find factorial
- Fibonacci series
- Fibonacci triangle
- Number triangle
- Alphabet triangle
- Armstrong numbers
- Palindrome numbers
- Swap number
- Reverse number
- Decimal to binary
- Assembly code in C
- Matrix multiplication
- HCF & LCM
- nCr & nPr
- Print pattern
- Floyd’s triangle
- Pascal triangle
- Count digits
- Strong numbers
- Perfect numbers
- Sum of natural number
- Binary to decimal
- Decimal to octal
- Octal to decimal
- Binary to octal
- Octal to binary
- Add using pointer
- Bubble sort
- Insertion sort
- Selection sort
- Quick sort
- Binary search
- Linear search
- Largest element of array
- Smallest element of array
- Reverse Array
- Variable size & limit
- ASCII value of character
- Sum of array elements
- Number of element in array
- Merge two array
- Insert element in array
- Delete element from array
- Add two matrix
- Transpose matrix
- Print string
- Reverse string
- Delete vowels
- Sort string
- Remove spaces
- Swap string
- Random numbers
- Print date & time
- Print IP address
- Shut down computer
Program to delete an element from C array
Here, we will see C program to delete element from array. Suppose, we have an integer type array of size 10 having 7 element which has the value assigned in it like as bellow;
int main_array[10] = {3, 4, 7, 8, 9, 11, 6};
Now we want to delete or remove an element from this array. Assume, we will remove the element from position three which is 7. So, the new array after deletion will looks like this;
int main_array[10] = {3, 4, 8, 9, 11, 6};
You may have noticed that every element which has the position after the deleted element has reduced their index by one. The total size of array remains same after deleting any element.
However, you can delete any element from an array. In this guide we will write a C program to delete an element from C array. Look at the following program.
C program to delete an element from array
// delete element from array in c
#include <stdio.h>
int main(){
int Num, x, main_array[30], del_posn;
printf("Enter how many integers in the array : ");
scanf("%d", &Num);
printf("\nEnter all array element here : \n");
for(x = 0; x < Num; x++){
scanf("%d", &main_array[x]);
}
printf("\nEnter the position from where you want to delete element : ");
scanf("%d", &del_posn);
if(del_posn >= Num + 1){
printf("\nValue not exist in the array.\n");
}else{
for(x = del_posn - 1; x < Num - 1; x++){
main_array[x] = main_array[x + 1];
}
printf("\nArray after deletion is : \n");
for(x = 0; x < Num - 1; x++){
printf("%d ", main_array[x]);
}
}
return 0;
}
Output of delete element program:

You can delete an element from an array using this process. It may be any type of array like integer, float, double or even character.
However, it is not recommended to follow this process of deletion of an element if the array size is large and need to shift many element. If we need to delete element frequently then it is not recommended at all. For that case we should use linked list data structure.
Previous page:Â Insert element in array
Next page:Â Add two matrix
Recommended for you: