TITLE: if $f$ is continuous on $\mathbb{R}$ and $f(r)=0,r \in \mathbb{Q}$, then $f(x)=0,x \in \mathbb{R}$
QUESTION [7 upvotes]: Suppose that $f:\mathbb{R} \rightarrow \mathbb{R}$ is continuous on $\mathbb{R}$ and that $f(r)=0$ for all $r \in \mathbb{Q}$. Prove that $f(x)=0$ for all $x \in \mathbb{R}$. 
My attempt: Define a sequence $(x_n)$ where $x_n \in \mathbb{Q}$ for all $n \in \mathbb{N}$ and assume that $(x_n) \rightarrow a \not\in \mathbb{Q}$. Since $f$ is continuous, we have $\lim_n{f(x_n)}=f(a)=0$. Since $a$ is arbitrary irrational number, we have $f(a)=0$ for all $a \not\in \mathbb{Q}$. Hence, we proved the statement.
Is my proof valid? or is there any flaw ?

REPLY [3 votes]: Assume $f$ is not identically zero, so there must exist some irrational $s$ such that $f(s) \neq0$, By continuity there is some neighbourhood of $s$ where $f \neq0$, but since $\mathbb Q$ is dense in $\mathbb R$, this is not possible. And you have your result.