1. ## Delete an array

Can someone explain to me the process of the array deletion.
steg by step so that i understand the whole process thank you. please dont forget to explain what happens in every loop and what happens to the delted array. does it become 0 or does it vanish and so forth

Code:
``` int i, varunummer;
soka(antal_varor, inventory);
for (;;)

{
int ja;

printf("\nVill du avregistrera en vara ja(1) eller nej(2) ");
scanf("%d", &ja);
if (ja==1)
{

// printf("du har valt att avregistrera en vara\n");
printf("Ange varunumret som du vill avregistrera?\n");
scanf("%d", &varunummer);
i = find_part(varunummer, antal_varor, inventory);

--*antal_varor;
for ( ; i < *antal_varor; i++)
inventory[i] = inventory[i + 1];

}```

2. Arrays don't vanish until they go out of scope.

Since you didn't actually post an array, it's hard to say what you're doing.

Non English variable names add no clarity either.

3. okay but what happens to an array when it is deleted

for example

[10, 20, 30, 40 , 50]

how does it work when we delete index position nr 2 = [30]

4. You don't delete an array, you delete an element inside an array. That happens by simply shifting all the elements after the one you want to delete one place to the left, overwriting it in the process. For example, if you know the index you can do:
Code:
```for (i = index; i < arraySize - 1; ++i) {
array[i] = array[i + 1];
}
--arraySize;```
The true, allocated size of the array though doesn't change, unless you use some realloc trickery.

5. Originally Posted by abmoh
okay but what happens to an array when it is deleted

for example

[10, 20, 30, 40 , 50]

how does it work when we delete index position nr 2 = [30]
Your array will end up containing
[10, 20, 40 , 50, 50]
With 4 valid elements.

The last array position doesn't go anywhere. As far as your program is concerned, it doesn't exist as a valid array slot, but the memory is still there for as long as the array exists. You can re-add a 5th element any time you like.