Looking at your first line of C-code:
y += a*(x-y)
It can be converted to an algebraic relation between the samples of the filter output sequence $y[n]$ and the filter input $x[n]$ as:
$$y[n+1]-(1-a)y[n]=ax[n]$$ which is also equivalent to
$$y[n]-(1-a)y[n-1]=ax[n-1]$$
And the associated transfer function of this filter is $$H(z) = \frac{a z^{-1}}{1 - (1-a)z^{-1}} = \frac{a z^{-1}}{1 + (a-1)z^{-1}}$$
Now your application will probably require a causal filter, (which means only current and past input is available and should be used to produce current output) in which case then the poles of the filter should reside inside the unit circle , i.e., $|z_p| < 1$.
Since this filter has a single pole which is at $z_p=(1-a)$ then we have; $|1-a| < 1$ and hence;
$$0 < a <2$$ is the allowed range of real $a$ for which you can have a stable and causal filter.
Now to have a casual and stable lowpass filter you require that the pole is along the positive side of the real line, i.e., $0 < z_p < 1$ which means that we require $0 < a < 1$.
Otherwise when $ 1 < a < 2$ the filter becomes a highpass filter (actually it will be some other form of high-boost or shelving type filter rather than a strict high-pass filter which should block low frequencies, which these filters won't), as the pole will become negative for that range of $a$.
Note also that $a=1$ produces output equal to input shifted by 1 samples: $y[n] = x[n-1]$
Below are a few frequency response plots for different values of valid $a$ range:
