Why is this argument invoking the mean value theorem incorrect? Where is the flaw in this argument?
Let $f^\prime (x)$ exist for $a < x < b$.  Let $a < c < b$.  Then if $h$ is chosen such that $ a < c + h < b$, the mean value theorem gives
$$
\frac{f(c+h) - f(c)}{h} = f^\prime (c + \theta \, h)
$$
where $0 < \theta < 1$.  Take the limit where $h \to 0$.  Then the left hand side tends to $f^\prime (c)$.  This implies that the limit of $f^\prime (c + \theta \, h)$ as $h \to 0$ exists and equals $f^\prime (c)$.  Hence, $f^\prime (x)$ is continuous at $x = c$.
This argument clearly cannot be correct.  Consider the example function
$$
f(x) = \begin{cases}
0 & \text{if } x=0,\\
x^2 \sin(1/x) & \text{otherwise}.
\end{cases}
$$
This function is continuous everywhere, and its derivative exists everywhere.  So it looks like the mean value theorem should apply for any interval I choose.  But its derivative is discontinuous at $x=0$, which contradicts the conclusion of the above argument.
 A: Let me give an example of a similar argument that makes it clearer what is wrong here.  Consider the function $g(x)$ given by $g(x)=1$ if $x\geq 0$ and $g(x)=0$ if $x<0$.  I will "prove" that $\lim_{x\to 0} g(x)=1$, and hence $g$ is continuous at $0$.
To do this, just consider the equation $1=g(h^2)$.  This equation is true for all values of $h$.  Now let's take the limit on both sides as $h\to 0$.  The left-hand side obviously converges to $1$.  Thus the right hand side converges to $1$, and since $h^2$ is approaching $0$ as $h\to 0$, this tells you that $g(x)$ converges to $1$ as $x$ goes to $0$.
This is obviously wrong, and the reason it's wrong should also hopefully be clear: the last clause of the last sentence doesn't follow.  We know that $\lim_{h\to 0} g(h^2)=1$, but this doesn't automatically imply that $\lim_{x\to 0} g(x)=1$, because as $h$ approaches $0$, $h^2$ does not cover every possible value $x$ can cover as $x$ approaches $0$ (it misses all the negative values).
So your argument has the same problem.  You know that $\lim_{h\to 0} f'(c+\theta(h)h)=f'(c)$ (here I'm writing $\theta(h)$ rather than just $\theta$, since $\theta$ actually depends on $h$).  But you can't conclude from this that $\lim_{x\to 0}f'(x)=f'(c)$, because you don't know that every $x$ close to $c$ can be written in the form $c+\theta(h)h$ for $h$ close to $0$.  The best you can say is that there exists a sequence of points $x_n\neq c$ converging to $c$ such that $\lim_{n\to\infty}f'(x_n)=f'(c)$ (for instance, let $x_n=c+\theta(1/n)/n$).  But to conclude that $\lim_{x\to c}f'(x)=f'(c)$, you would need to know this for every sequence $(x_n)$ which converges to $c$, and you don't know that.
A: You have shown that for all $h$ such that $a < c+h < b$ there exists some $\theta \in [0,1]$ such that
${ f(c+h)-f(c) \over h} = f'(c+\theta h)$.
In this context, we have that for all $h_k \to 0$, there exists $\theta_k$ such that ${ f(c+h_k)-f(c) \over h_k} = f'(c+\theta_k h_k)$. In particular,
$\lim_k f'(c+\theta_k h_k) = f'(c)$.
It does not state that for all $h_k \to 0$ that $\lim_k f'(c+ h_k) = f'(c)$.
In the particular example you gave, it is clear (because $f$ has maxima and minima arbitrarily close to zero)
that for any $\epsilon>0$ there are points $-\epsilon < x_k < 0 < y_k < \epsilon$ such that
$f'(x_k) = f'(y_k) = 0$.
Hence for any $h$, there is some $\theta \in [0,1]$ such that $\theta h$ is
one of the zeros of $f'$.
A: Theta is not fixed, but depends on h.
