# Reference point of electric potential

If we have a charge density that depends only on $z$ (i.e. $y$ and $x$ are infinite) and of the form $$\rho(z)=Cz^2, \qquad z\in[-d/2,d/2]$$ then when calculating the electric field one finds: $$E=\frac{Cz^3}{3\epsilon_0}, \qquad z\in[0,d/2]$$ and $$E=\frac{Cd^3}{24\epsilon_0}, \qquad z\in[d/2,\infty[.$$

I know I can figure out the potential using a contour integral of the electric field from a reference to an arbitrary point on the field. However, why can I not set the potential to be zero at infinity, and even more importantly, why can I set the potential to zero at $z=0$?

The only thing that matters is the difference of potential between two points. So if you have a given potential $V_0(z)$ that has a finite value at $z=0 \,$ (which is the case here for the one you would deduce directly from your equations), any potential $V_a(z)$ of the form $$V_a(z)=V_0(z)+a$$ is valid.
In particular, the potential $V_{-V_0(0)}(z)$ is valid. What is its value at $z=0$? By definition, it is $$V_{-V_0(0)}(0)= V_0(0)+(-V_0(0))=0.$$
That explains why you can set the potential to zero at $z=0$ by selecting this particular potential $V_{-V_0(0)}(z)$.
Regarding infinity, if $V_0(z)$ is infinite at $\infty$ (which is the case here for the one you would deduce directly from your equations), $V_a(z)$ will remain infinite at $\infty$ because $a+\infty=\infty$ for all real number $a$.