Why are dense set useful in analysis Consider the following theorem from Rudin's Real-and complex analysis.
3.14 Theorem For $1 \leq p < \infty, C_c(X)$ is dense in $L^p(\mu)$.
What I don't understand is why this result is useful in proofs. I heard few examples of where in order to define functionals in $L^p(\mu)$ you can firstly define them in $C_c(X)$ and then extend them using Hahn Banach theorem.
Is this the main application? definition of maps and functionals?
Update: If anyone could point to the proofs of results that actually use density of $C_c(X)$ in $L^p(\mathbb{\mu})$ that would be useful.
 A: This is one of the most important results in real/functional analysis. It is used in proofs of other important real/functional analysis theorems. One I can think of is the famous transformation formula.
Your theorem is especially important in the case $X = \mathbb{R}^n$ (or sufficiently regular subsets of the latter) and $\mu$ being the Lebesgue-measure. The next step is to prove that $C^\infty(\mathbb{R}^n) \cap W^{1, p}(\mathbb{R}^n)$ is dense in the sobolev spaces $W^{1, p}(\mathbb{R}^n)$ where $1 \leq p < \infty$. Consequences of this are e.g. the chain rule for Sobolev functions, fundamental theorem of calculus for Sobolev functions etc... . The argument is always to prove the desired result for a differentiable function, which is usually a classical calculus I,  II or III result. Then we prove that if we approximate (into the Sobolev space) the classical result will not be distorted. So we use the dense set, because it has some nice properties that we did not enjoy before.
Some more (huge) consequences of your theorem are the Fundamental theorem of Calculus of Variations (and therefore the Euler-Lagrange-Eq.), Poincaré's-inequality (and therefore existence of weak solutions for elliptic PDEs like the Dirichlet-PDE), continuity of the trace operator for sobolev spaces, Gagliardo-Nirenberg type inequalities (and therefore Sobolev-embeddings which have countless applications in PDE theory) and plenty plenty more.

One additional remark: Assume that $V$ and $Y$ are Banach spaces, $A \subseteq V$ is dense and $T:A \rightarrow Y$ is a countinuous, linear functional. You can explicitly use density here (note that Hahn-Banach does not apply if $Y \neq \mathbb{R}$) to extend $T$: Let $v \in V$ and $(v_k)_{k \in \mathbb{N}} \subseteq A$ a sequence that converges to $v$ (i.e. it is Cauchy). Then
$$
\lVert Tv_k - Tv_m \rVert_Y \leq \lVert T \rVert \lVert v_k - v_m \rVert_V \overset{k, m \rightarrow \infty}{\longrightarrow} 0
$$
So $(Tv_k)_{k \in \mathbb{N}} \subseteq Y$ is Cauchy and therefore, because of $Y$ being Banach, has a limit $\tilde{v}$. We can then set $Tv := \tilde{v}$.
