I am working on the following exercise:
Consider a holomorphic function $f$ with a connected domain and $Im(f) = 0$. Show that $f$ is constant.
I solved it in the following way: Recalling the Cauhy-Riemmann Differential Equations the we have that the partials of $Re(f)$ have to be zero. So said partials are constant and thus continuous, so we know that $f$ is differentiable and we can apply the Mean Value Theorem.
But why is it required that the domain is connected? Could you explain?
The mean value theorem does not apply when the domain is not connected.
Compare with the following example of real analysis (really the same is going on in the complex plane, but at this point you probably have a better intuition about real-valued functions): Define
$$f: ]-2,-1 [\cup]1,2[\to \mathbb{R}: x \mapsto \begin{cases}-1 \quad -2 < x < -1 \\ 1 \quad 1 < x < 1\end{cases}$$
Then $f' = 0$ but $f$ is not constant.
In other words, on each connected component your function must be constant, but this does not mean the function is constant everywhere.