Construction of a function which is not the pointwise limit of a sequence of continuous functions This is somewhat linked to a prior question of mine which was looking to see if a proof of mine regarding the Dirichlet function was correct (it wasn't). I now have an answer to the question which can be answered without using directly using the Baire category theorem or the likes; as it is sufficiently different to my original approach, I feel that a new question would be the best way of going about this.
The question is to

Construct a function $f:[0,1] \rightarrow \mathbb{R}$ which is not the pointwise limit of any sequence $(f_n)$ of continuous functions

to which I will have an answer below (while I didn't come up with much of this myself, I feel it's an interesting result to discuss).
Finally, as a warning to those who are seeing this as a result of searching for answers to their example sheet/homework questions, please have a think about the question before reading the answer below.
 A: See this answer for examples. (A function is in Baire class one iff it is the pointwise limit of continuous functions, in Baire class two iff it is the pointwise limit of Baire class one functions, etc. The answer shows "natural" examples of functions in Baire class two but not Baire class one.)
One can in fact do better, and show that the sequence of Baire classes is rather long (it has length $\omega_1$, the first uncountable ordinal). A high level sketch of this fact uses some ideas of descriptive set theory. I follow here A.C.M. van Rooij, and W.H. Schikhof, A second course on real functions, Cambridge University Press, 1982. Stronger results can be found in A. Kechris, Classical descriptive set theory, Springer, 1995.
First, given a class $\mathcal A$ of functions on $\mathbb R$, define $\mathcal A^*$ as the class of pointwise limits of functions from $\mathcal A$, so if $\mathcal A$ is the class $\mathcal B^0$ of continuous functions (that is, Baire class zero functions), then $\mathcal A^*=\mathcal B^1$ is the the class of Baire class one functions, $(\mathcal A^*)^*=\mathcal B^2$ is the class of Baire class two functions, etc.
The Borel measurable functions are the closure of the continuous functions under the operation of taking pointwise limits.
Call a function $F:\mathbb R^2\to\mathbb R$ a catalogue of $\mathcal A$ iff $F$ is Borel measurable and for every $f\in\mathcal A$ there is an $s\in[0,1]$ such that $f(x)=F(x,s)$ for all $x$. (We can think of $s$ as a "code" for $f$.) Note that we are not requiring that for each $s\in[0,1]$, the function $f(x)=F(x,s)$ be in $\mathcal A$.

Theorem.

*

*If $\mathcal A_1,\mathcal A_2,\dots$ have catalogues, then so does $\bigcup_n \mathcal A_n$.


*If $\mathcal A$ has a catalogue, so does $\mathcal A^*$.


*The class $\mathcal B^0$ of continuous functions has a catalogue.


*The class of Borel measurable functions has no catalogue.


*If $\mathcal A$ is a class of functions that contains all the continuous functions and has a catalogue, then $\mathcal A^*\ne\mathcal A$.

The proof of item 4. is a diagonal argument: If $F:\mathbb R^2\to\mathbb R$ is a catalogue for the Borel measurable functions $f:\mathbb R\to\mathbb R$, then $g(x)=F(x,x)$ and $1+g$ are Borel measurable. So there must be $s$ such that $1+g(x)=F(x,s)$ for all $x$, in particular for $x=s$, so $1+g(s)=g(s)$, a contradiction.
Item 5. follows, because if $\mathcal A$ contains the continuous functions, and $\mathcal A=\mathcal A^*$, then $\mathcal A$ contains the Borel measurable functions. If $\mathcal A$ admits a catalogue, then so would the subclass of Borel measurable functions, but we just proved this is not the case.
For item 1, suppose $F_n$ is a catalogue of $\mathcal A_n$ for all $n$. The functions $(x,y,z)\mapsto F_n(x,y)$ and $(x,y,z)\mapsto\chi_{\{1/n\}}(z)$ are Borel measurable functions on $\mathbb R^3$, but then so is
$$ H(x,y,z)=\sum_n F_n(x,y)\chi_{\{1/n\}}(z). $$
Recall now that there are continuous functions $p_1,p_2:\mathbb R\to[0,1]$ such that if $p(x)=(p_1(x),p_2(x))$, then the restriction of $p$ to $[0,1]$ is a surjection of $[0,1]$ onto $[0,1]^2$.
Let $$ F(x,s)=H(x,p_1(s),p_2(s)). $$
Then $F$ is a catalogue for $\bigcup_n\mathcal A_n$.
For item 2., we can similarly find continuous functions $p_1,p_2,\dots$ such that for any $y_1,y_2,\dots\in[0,1]$ there is an $x\in[0,1]$ such that $p_i(x)=y_i$ for all $i$. Now define
$$ F^*(x,s)=\left\{\begin{array}{cl}\lim_n F(x,p_n(x))&\mbox{ if the limit exists,}\\ 0&\mbox{ otherwise.}\end{array}\right. $$
If $F$ is Borel measurable, so is $F^*$, and it is easy to see that if $F$ is a catalogue for $\mathcal A$, then $F^*$ is a catalogue for $\mathcal A^*$.
Finally, we reach item 3., the crux of the matter. We want to show that the class of continuous functions has a catalogue. For this, note first that $\{f\}$ has a catalogue for each continuous $f$. It follows that the class $\mathcal P$ of polynomials with rational coefficients has a catalogue, by item 1. But then, by item 2, so does $\mathcal P^*$. Now we can use Weierstrass approximation theorem to see that $\mathcal P^*$ contains all the continuous functions, and we are done.

To close, note that if the goal is simply to show that there are functions not in $\mathcal B^1$ (rather than to display the long Baire hierarchy, or to indicate explicit examples as in the link above), then a simple cardinality argument is possible: There are $\mathfrak c=2^{\aleph_0}=|\mathbb R|$ many continuous functions: There can be no less, because the constant functions are continuous, and we do not have more, because a continuous function is determined by its values on the countable set of rationals. Now, there are only $$|\mathbb R^{\mathbb Q}|=|\mathbb R|^{|\mathbb N|}=(2^{\aleph_0})^{\aleph_0}=2^{\aleph_0}=\mathfrak c$$ many functions from the rationals to the reals, and the continuous functions correspond to a (proper) subset of them.
Finally, if a function is a pointwise limit of continuous functions, then it is determined by a countable sequence of such functions, and there are, again, only $\mathfrak c^{\mathbb N}=\mathfrak c$ many such sequences. So $|\mathcal B^1|=\mathfrak c$. But there are $\mathfrak c^{\mathfrak c}>\mathfrak c$ many functions from $\mathbb R$ to itself, so not all of them can be in $\mathcal B^1$.
(Continuing this argument further, we see that, even if we take all the Baire functions together, not just those of class $1$, we still only have $\mathfrak c$ many functions, so there are functions that are not in any of the Baire classes.)
A: The result follows quite nicely from another result (which nicely happened to also be from our question sheet, but hey), which I will now state:

Theorem -If $(f_n)$ is a sequence of continuous functions $[0,1] \rightarrow \mathbb{R}$ converging pointwise to a function $f$, then there is some subinterval $ [a,b] \subset [0,1]$ with $a < b$ on which $f$ is bounded.

This happens to answer the original question, as then we have a counterexample if we can construct a function which maps any subinterval of $[0,1]$ to the whole of $\mathbb{R}$, of which two examples come to mind:


*

*The Conway base 13 function - For an explanation of what this function is, I would suggest reading the following from Willie Wong's blog; the Wikipedia page doesn't seem to be too good

*An adapted Thomae's function - Here we define $f: [0,1] \rightarrow \mathbb{R}$ by
$$f(x) = \begin{cases}
q,  & \text{if $x \in \mathbb{Q}$, $x=p/q$ irreducible} \\
0, & \text{if $x \notin \mathbb{Q}$}  \\
\end{cases} $$ 
Now, the above theorem is usually proven by some version of the Baire Category Theorem; however, it can be proven in an "elementary" way, although the proof is still heavily inspired by the theorem. (I have various friends/supervisors to thank for the proof of this:)

Proof - Let us assume the opposite for a contradiction;
  suppose a sequence $(f_n)$ of continuous functions converges pointwise
  to a function $f$ which is unbounded on any subinterval of $[0,1]$.
  Thus, we can pick $x_0 \in [0,1]$ such that
$$ f(x_0) \geq 2^0 + 2$$
and thus as $f_n$ converges pointwise to $f$, we certainly have a
  $n_0$ such that 
$$f_{n_0}(x_0) \geq 2^0 + 1$$
(if this seems mystifying, then write out the definition of pointwise
  convergence of a sequence of functions and it should be clear - infact
  the above holds for all $n \geq n_0$ but this isn't needed); thus as
  $f_{n_0}$ is continuous on $[0,1]$, we can find an interval $I_0 =
> [x_0 - \epsilon_0, x_0 + \epsilon_0 ]$ for some $\epsilon_0 > 0$ such
  that  $$ f_{n_0}(x) \geq 2^0 \; \text{for all $x \in I_0$} $$
Now, consider $f$ restricted to $I_0$; but then $f$ is unbounded on
  $I_0$ so we can find an $x_1 \in I_1$ such that $f(x_1) \geq 2^1 + 2$.
  Then by the pointwise convergence of $f_n$ we can find a $n_1$ such
  that $f_{n_1}(x_1) \geq 2^1 + 1$ and by continuity of $f_{n_1}$ there
  exists a closed interval $I_1$ with $x_1 \in I_1 \subset I_0$ and
  $f_{n_1}(x) \geq 2^1$ for all $x \in I_1$. But then $f$ is unbounded
  on $I_1$ $\ldots$ 
We can then generalise inductively to build a nested sequence of
  closed, non-empty intervals
$$ I_k \subset I_{k-1} \subset \ldots \subset I_1 \subset I_0 \subset [0,1]$$
such that $f_{n_k} \geq 2^k$ for all $x \in I_{k}$. Now, there are
  various ways of arguing that 
$$ \bigcap_{k=0}^{\infty} I_k$$
is non-empty; a completeness argument suffices (I won't outline it
  here, but it isn't too hard), so we can find a $y \in I_k$ for all
  $k$; then
$$ f_{n_k}(y) \geq 2^k \; \text{for all $k$}$$
which is absurd if $f_n$ converges to $f$ pointwise. $\square$

While the original question has now been answered, it leaves something to be desired in the sense that we would want to find counterexamples which aren't as badly behaved, such as $1_{\mathbb{Q}}$, the indicator function of the rationals. We can do this by using the Baire Category Theorem in some form, but at this point there's not really any way we can do this other than developing the theory again.
