Let $f : \left[0,\frac{2}{\pi}\right] \rightarrow \mathbb{R}$ be defined by $f(0)=0$ and $f(x)=x^2\cos\left(\frac{1}{x}\right)$ for $x\neq 0$.
This function is continuous on $\left[0,\frac{2}{\pi}\right]$ so the set of its zeros i.e.
$$ Z=\left\{x \in \left[0,\frac{2}{\pi}\right] : f(x)=0\right\} $$
is compact (closed and bounded).
Is $Z$ a connected set?
Please show the connectedness if it is connected and provide counterexample if it is not.
Just to elucidate @suchan's answer
A space $X$ is connected if and only if the only subsets of $X$ which are both open and closed (clopen sets) are $X$ and the empty set.
And a subspace topology on $Y \subset X$ is defined by: $U \subset Y$ is open (or closed) if and only if $U = Y \cap V$, where $V$ is an open (or closed ) set in $X$.
With this, note that $$Z = \{0\}\cup\left\{\frac{2}{(2n+1)\pi} : n \geq 0\right\} \subset \mathbb{R}$$
Then look at $\left\{\frac{2}{3\pi}\right\} \subset Z$ $$\left\{\frac{2}{3\pi}\right\}=Z \cap \left\{\frac{2}{3\pi}\right\}, \text{ where as we know }\left\{\frac{2}{3\pi}\right\} \text{ is closed in }\mathbb{R};\text{ and}\\ \left\{\frac{2}{3\pi}\right\}=Z \cap \left(\frac{2}{5\pi},\frac{2}{\pi}\right), \text{ where as we know }\left(\frac{2}{5\pi},\frac{2}{\pi}\right) \text{ is open in }\mathbb{R}$$
Therefore $\left\{\frac{2}{3\pi}\right\} \subset Z$ is a clopen set, and hence $Z$ is not connected.
A slightly different approach
We'll first show that $A = Z \setminus \left\{\frac{2}{3\pi}\right\}$ is open in $Z$. Choose $y \in A$ and we set $\delta = \left|y - \frac{2}{3\pi}\right|$, then since $\frac{2}{3\pi} \notin B(y,\delta) \implies B(y,\delta) \subset A$, hence $A$ is open in $Z$
Take $a=\frac{2}{3\pi} \in Z$, then $B_Z(a,\epsilon)=\{x \in Z : |x-a|<\epsilon\}$. Taking $\epsilon=1/2$, you'll see that $$B=B_Z\left(\frac{2}{3\pi},\frac{1}{2}\right)=\left\{\frac{2}{3\pi}\right\}$$ Therefore, $B$ is open in $Z$.
Now, you can write $Z = A \sqcup B$, so $Z$ is not connected.