From: (e-mail address removed)
(your third case
That's bad style of coding. You have a/b really close together with no
spaces, but you have (float) spaced away from it, so it looks visually
like a/b happens first then the quotient is cast to float.
The correct way to punctuate your third case, to make it clear, is :
c = (float)a / b;
Rather than memorizing operator precedence and often making mistakes, I
suggest always using an extra level of parens whenever you're not sure:
c = (float)(a/b); /* Your second case, as you had it */
c = ((float)a)/b; /* Your third case, made more clear here */
If you have enough parens, you don't need any spaces, but to use spaces also:
c = (float) (a/b);
c = ((float)a) / b;
If you use parens, but also use spaces, but the spaces are in the wrong
places for visual effect consistent with parens, you'll get this clash:
c = (float)(a / b);
c = ((float) a)/b;
Just one glance at that last one shows you something is screwed!
The same problem happens with poorly punctuated:
c = a+b / a-b;
which really means:
c = a + (b/a) + b;
but what was really intended was probably this:
c = (a+b) / (a-b);
where parens are needed to make it work as intended.
The whole mess with operator precedence sucks.
If you dislike it as much as I do, use Lisp instead.
By the way, for a C-like language, I wonder why nobody thought of
the idea of having the number of spaces determine the precedence?
Operations with no spacing would be performed first, then operations
with one space, then two etc. Then the following would be correct per
their visual appearance:
c = a+b / a-b;
v = a * x**2 + b * x + c;
Meanwhile, back in C, it would be nice if the compiler would warn about
spacing that is inconsistent with operator precedence.