I want to make function that throws out number x from an array and then updates size of that array (n) through reference on (n).

For example i have array a[] = 3, 4, 2, 1, 4; it's size is 5. If i choose my x element to be 4 my array should become 3, 2, 1; and it's size should be 3.

This is how my function looks, it actually removes first 4 but when it finds second 4 it changes it to 0.

```
void throwOut(int a[], int& n, int x)
{
    int i;

    for ( i = 0; i < n; i++)
    {
        if (a[i] == x)
        {
            for (; i < n - 1; i++)
            {
                a[i] = a[i + 1];
            }

            a[i - 1] = 0;
            n -= 1;
        }
    }
}

```