Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //operator precedence exercise (use the debugger)
- int main() {
- float x = 3;
- float a = x*x / 4 + 1;
- float b = (x*x) / 4 + 1; //these three are all the same
- float c = ((x*x) / 4) + 1; //but I think this is clearer
- a = 2.0f;
- b = 1.0f;
- c = 3.0f;
- float result1 = a / b * c; //ambiguous (in mathematics)
- float result2 = (a / b)*c; //this is how C++ evaluates it
- float result3 = a / (b*c); //we can change the order using parenthesis
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement