It's pretty apparent $\int_{-\pi}^{\pi} \cos nx \, dx$ should be 2$\pi$ when n = 0. However it seems $\int_{-\pi}^{\pi} \cos nx \, dx$ is always 0 when actually integrated given that n is integer. I have no idea why we can't get the same answer.
$ \begin{align} \int_{-\pi}^{\pi} \cos nx \, dx& = \left [\frac{1}{n} \sin nx \right ]_{-\pi}^\pi \\&= \frac{1}{n} \sin n\pi - \frac{1}{n} sin {(-n\pi)} \\&= \frac{1}{n} \sin n\pi + \frac{1}{n} \sin n\pi \\&= \frac{2}{n} \sin n\pi \\&= 0 \end{align} $
Well, if $n=0,$ then what can $\frac1n\sin nx$ even mean?
For non-zero constants $\alpha,$ we certainly have $\frac1\alpha\sin\alpha x$ as an antiderivative of $\cos\alpha x;$ however, if $\alpha=0,$ then $\cos\alpha x=1$ for all $x,$ and so does not have a periodic antiderivative.