All the cases when I have failed to programm bug free and was searching for many hours for the most irrational and simple error
| cout << 24 * (1 / 24); | One might wonder what might be printed on screen. Well, it will be 0. Unless we explicitly cast the division to double. A classic. |
|
long a = 10; double b = 0.5; long c = (long) b * a; | This is actually the previous exaple the other way round -- means if you learn to avoid one problem it comes back and hits you from the other side. The idea is that I used the cast to explicitly tell the compiler I need it here and that it does not need to complain about it. What I have forgotten are the parenthesis around the whole b*a expression. Took 3 hrs to figure out. Refactor AND test. Do not: refactor, refactor, refactor, refactor and then test. |