Let $M$ be an $m$-dimensional manifold and $N$ be an $n$-dimensional manifold. Suppose also that the topology on $N$ can be described by a metric. Thus, the set $C(M,N)$ can be endowed with the topology of [uniform convergence on compacta][2]. 


Let $N'\subseteq N$ be a dense subset which is homeomorphic to $\mathbb{R}^n$. In this [post's](https://mathoverflow.net/questions/354304/density-of-continuous-functions-to-interior-in-set-of-all-continuous-functions) answer's comment it was remarked that $C(D,D-\{0\})$ is not dense in $C(D,D)$ where $D$ is the unit disc. 


In general, when is $C(M,N')$ *not* dense in $C(M,N)$?



Non-density of continuous functions to interior in set of all continuous functions
1) About Erz' answer, and Annie's second question. It is a general property that for two differentiable manifolds $M$, $N$, such that $M$ is compact, and given a continuous map $f:M\to N$, any continuous map $g:M\to N$
close enough to $f$ is homotopic to $f$. This can be proved by many different ways, depending on taste. (One can assume that $N$ is also compact, since
we are only interested in a small neighborhood of the compact $f(M)$ in $N$):


a) Put a Riemannian metric on $N$, let $i>0$ be its injectivity radius: any two points $x,y\in N$ whose distance is less than $i$ are linked by a unique shortest geodesic, and this geodesic depends continuously on the pair $(x,y)$. Then, assuming that $d(f(x),g(x))<i$ for every $x\in M$, the geodesics from $f(x)$ to $g(x)$ provide the desired homotopy;


b) Embed $N$ in $R^n$ for $n$ large enough (Whitney); then $N$ has a tubular neighborhood $T$ in $R^n$ together with a continuous retraction $p:T\to N$; if $g$ is close enough to $f$, then the segments $[f(x),g(x)]$ in $R^n$ are contained in $T$ and
their projection under $p$ provide the homotopy;


c) Triangulate $N$ and use the straight lines in the simplices of the triangulation instead of the geodesics;


d) Use a good cover of $N$ by open subsets $U(i)$ such that every intersection
$U(i\_1)\cap\dots\cap U(i\_k)$ which is nonempty is contractible...


2) Erz' homotopical argument is excellent;
 but even if $N$ is contractible, $C(M,N')$ is in general not dense in $C(M,N)$.
 We should think to the complement $X$ of $N'$ in $N$.
For example, let $M$ be the compact interval $[-1,+1]$, $N$ be the complex plane $\mathbb{C}$ and $X$ be the nonpositive real halfline $\mathbb{R}\_-$. Clearly, $\mathbb{C}\backslash X$ is diffeomorphic with the plane (being open and starred with respect to $1$.) Then, the embedding $[-1,+1]\to\mathbb{C}$: $t\mapsto-1+it$ can certainly not be approximated by continuous maps valued in $\mathbb{C}\backslash X$ (by the elementary "intermediate value theorem").


More generally, note that by Weierstrass' approximation theorem,
Annie's question is equivalent to: when is $C^\infty(M,N')$ not $C^0$-dense
in $C^\infty(M,N)$? The advantage of this differentiable setting is that
thanks to Thom's transversality theorem, one can answer in
all cases where $X$ is regular enough (technically, a finite or denumerable
union of smooth submanifolds $S\_i\subset N$; e.g.
a polytope):


a) If one at least of the $S\_i$'s is of codimension $\le m$ in $N$, then
there will be a smooth map $f:M \to N$ which intersects $S\_i$ transversely in at least one point; and $f$ cannot be in the $C^0$-closure of $C(M,N')$.


b)
If on the contrary each $S\_i$ is of codimension $>m$ in $N$, then by Thom's transversality theorem, $C^\infty(M,N')$ is $C^\infty$-dense in $C^\infty(M,N)$, and in particular $C^0$-dense. (As to Erz' second question: since $\dim(M)+\dim(S\_i)<\dim(N)$, saying that $f:M\to N$
is transverse to $S\_i$ amounts to say that $f(M)$ does not meet $S\_i$).


