Show that if $f:\mathbb{R}\rightarrow \mathbb{R}$ is continuous and $f(x)=0$ for all $x\in \mathbb{Q}$, then $f(x)=0$ for all $x\in \mathbb{R}$. I was proving the statement "if $f:\mathbb{R}\rightarrow \mathbb{R}$ is continuous and $f(x)=0$ for all $x\in \mathbb{Q}$, then $f(x)=0$ for all $x\in \mathbb{R}$."
My idea was that if $f(x)=a$ for any $a\neq 0$ and for any $x\notin \mathbb{Q}$, then the  theorem of continuity won't work for all $\varepsilon $.
Precisely,
Let $a$ be any real number such that $a\neq 0$.
Suppose that $f(x)=0\; \forall x\in \mathbb{Q}$, and $f(x)=a\;  \forall x\notin \mathbb{Q}$.
Since $f$ is continuous on $\mathbb{R}$, it is continuous at $x_{0}\in \mathbb{Q}\subseteq \mathbb{R}$.
Thus, $\forall\varepsilon> 0$, $\exists \delta > 0$ s.t
$x\in \mathbb{R},\left | x-x_{0} \right |< \delta$ implies $\left | f(x)-f(x_{0}) \right |<\varepsilon  $.
If $x\notin \mathbb{Q}$, then $\left | f(x)-f(x_{0}) \right |=\left | a \right |$.
This implies that for $x\notin \mathbb{Q}$, we can't pick any $\varepsilon$ s.t $0<\varepsilon\leq \left | a \right |$.
But, by the theorem, we must be able to pick any $\varepsilon>0$.
Therefore, this is a contradiction.
Thus, $f(x)\neq a\;  \forall x\notin \mathbb{Q}\Leftrightarrow f(x)=0 \; \forall x\notin \mathbb{Q}$
Hence, $f(x)=0 \; \forall x\in \mathbb{R}$ $$\blacksquare $$
However, my proof seems wrong, but I can't tell why. "If there is something to fix," which part should I fix, and which way is better to prove this statement?
 A: On the contrary, your approach is good. What I will say is that the presentation needs some tidying, which I suspect is the source of your doubt. Let's try putting it in a slightly different order:
Suppose $f(x_0) = a \neq 0$. Since $f$ is continuous, it is continuous at $x_0$. Considering $\varepsilon = |a| \neq 0$, there exists some $\delta > 0$ such that
$$|x - x_0| < \delta \implies |f(x) - a| < |a| \implies |a| - |f(x)| < |a| \implies |f(x)| > 0 \implies f(x) \neq 0.$$
Thus, every point $x \in (x_0 - \delta, x_0 + \delta)$ satisfies $f(x) \neq 0$. But, since $\Bbb{Q}$ is dense in $\Bbb{R}$, there must exist a rational point $q \in (x_0 - \delta, x_0 + \delta)$, which satisfies $f(q) = 0$. This is a contradiction.
A: It is enough to know this well fact . If $f,g\colon \Bbb R \to \Bbb R$ continuous functions and $$f(x)=g(x)$$ for all $x\in D$ where $D$ is dense subset of $\Bbb R$ then $f(x)=g(x)$ for every $x\in \Bbb R$ chekc?
Now, $f(x)=O(x)$ for every $x\in \Bbb Q$ where $O$ is a zero function. By using the fact above $f(x)=0$ for every $x\in\Bbb Q$
A: Just to prove that for any $\epsilon > 0 $ have the following,
$$
|f(x)|<\epsilon
$$
this implies that $f(x) \equiv 0$
what we know is $f(x) = 0$ for $x\in\mathbb{Q}$,
for $x \not\in \mathbb{Q}$ , we can find a sequence $x_n \in \mathbb{Q}$ such that $x_n \to x $ as $ n \to \infty $, because $f$ is continuous , that means for any $\epsilon > 0$ ,we can find the $\delta > 0$ such that only $|x_n-x| < \delta $ for some $n>N$ , there have the following
$$
|f(x_n)-f(x)| < \epsilon 
$$
note that $f(x_n) = 0$ , then we get what we want to prove.
A: Here's a neater proof:
Let $x\in \mathbb{R}$. It suffices to show that $|f(x)|=0$. Let $\epsilon>0$. As $f$ is continuous on $\mathbb{R}$, there exists some $\delta>0$ such that whenever $y\in (x-\delta,x+\delta)$ then $|f(x)-f(y)|<\epsilon$. So in particular choosing a rational $q$ in $(x-\delta,x+\delta)$, we have $|f(x)-f(q)|=|f(x)|<\epsilon$.  $\square$
Additionally, let us adapt the technique in the proof above to the following result:
Proposition:
Let $D\subseteq \mathbb{R}$ be a dense subset. Suppose $f,g:\mathbb{R}\rightarrow \mathbb{R}$ are continuous and they agree on $D$. Then $f=g$ on $\mathbb{R}$.
Proof:
It suffices to show that if $h: \mathbb{R}\rightarrow \mathbb{R}$ is a continuous function such that $h=0$ on $D$ then $h=0$ on $\mathbb{R}$.
Let $x\in \mathbb{R}$ and $\epsilon>0$. By continuity of $h$ on $\mathbb{R}$, there exists some $\delta>0$ such that whenever $y\in (x-\delta,x+\delta)$ we have $|h(x)-h(y)|<\epsilon$.
As $D$ is dense in $\mathbb{R}$, $D\cap (x-\delta,x+\delta) \neq \varnothing$. Thus picking one element, $d$, from the intersection we obtain $|h(x)-h(d)|=|h(x)|<\epsilon$. $\square$
