Let me convert my comments into an answer. First of all, given any closed subset $E\subset R^n$ there exists a $C^\infty$ function $f: R^n\to [0,\infty)$ such that $E=f^{−1}(0)$. See for instance
here. In particular, the boundary of your set $S$ can be as bad as you wish, for instance, it can be the Koch snowflake or a Cantor subset of $R^2$, or the Menger curve in $R^3$, etc. In particular, even if you $S$ is connected, its boundary need not even be a topological manifold.
The "correct" assumption to make is that $0$ is a regular value of $f$, i.e. for every $x\in f^{-1}(0)$, $\nabla f(x)\ne 0$. Then the Implicit Function Theorem will imply that $f^{-1}(0)$ is a smooth submanifold of dimension $n-1$. See for instance this wikipedia article. My favorite reference for this staff is Guillemin and Pollack "Differential Topology".
You then can prove (quite easily) that
$$
f^{-1}(0)= \partial S,
$$
where $S=\{x: f(x)>0\}$.