Prove that if $X\subset \mathbb R$ and if every continuous function $f:X \to \mathbb R$ is bounded. Then $X$ is compact.
My proof in $\mathbb R$ is only this. It's clear that if $X$ is compact, it's true. If $X$ is not compact in $\mathbb R$, it's because it's not bounded, and in this case for example, the identity function is continuous on $X$ (restriction of continuous function are continuous because are the composite of the inclusion of $X$ on $\mathbb R$ and the identity on $\mathbb R$, and both are continuous). If it's not closed, it doesn't have some limit point, say $a$; I think that the function $f ( x) = \frac{1} {{x - a}}$ is continuous and also unbounded ( I'm not completely sure of the continuity).
Here I used the characterization via closed and bounded, but, how general is this result? It is true in metric spaces? Or in topological spaces? My proof will not serve for this cases.