Physics and Astronomy |
Back to top
On this page
Contents Curing bracketitusExperience shows that some students have a habit of putting brackets everywhere, even when they are not needed: a = (b) + (c*d); // Don't do this x = (y) + (2 * (y*z)); // or this presumably because they aren't quite sure whether they need brackets or not. This is a bad idea because:
Mathematical precedenceThe "mathematical" operators * / % + - have exactly the same effect as in ordinary maths, with % being treated on the same basis as * and /, that is to say:
No implicit multiplicationIn maths we often use implicit multiplication with single-character variable names: s = ut + 0.5at2 expands to: s = u*t + 0.5*a*t*t Once we understand the implicit multiplication convention we see that C's treatment of */+- is exactly the same as we have been used to. |