The answer, even in a perfect world with ideal lossless components, is very surprising.
Like the other poster said, the energy in a capacitor is E = (1/2)CV
2Suppose I have a capacitor charged with voltage V, and I connect it through a resistor (R) to another capacitor of the same value with initially no voltage. The total energy in the system before connecting the second capacitor is (1/2)CV
2.
At some time, the voltage between the capacitors is the same, and current stops flowing. The energy in the system is then 2 x (1/2)CV
T2, where V
T is the terminal voltage. There are several ways to figure V
T, but here's one. The voltage of the first capacitor will decrease with a time constant of RC/2 (since the two capacitors in series will have a combined capacitance of C/2). So the voltage equation for the first capacitor is V x e
-t/(RC/2). The second capacitor will similarly charge with the equation V x (1-e
-t/(RC/2)). If you figure out where these two equations are equal, you will find that it is at t=-(RC/2) x ln(1/2), and if you plug that back into the voltage equations, will find that the final voltage is V/2, and is
independent of R and C.
So the energy in the system in the final state is 2 x (1/2)(V/2)
2 = (1/4)CV
2. So we have lost half of our energy. Where did it go? If you do the math, you will find that the energy is disipated in the resistor. But the really crazy thing is (and I encourage you to do the math), as is the final voltage state of the system, it is
independent of R. When you are through manipulating the equations, you find that R falls out, and the energy lost is purely a function of V and C. So even if the resistance is zero, the energy is still lost in the resistor.

Try it (calculating the energy lost in the resistor). I=V/R. P=VI. E=integral of P over time. If you do the integration, you will get a result of E=(1/4)CV
2 (R drops out of the equation). It's bizzare.