ulfben

Operator precedence

Sep 4th, 2017
757
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. //operator precedence exercise (use the debugger)
  2. int main() {
  3.     float x = 3;
  4.     float a = x*x / 4 + 1;  
  5.     float b = (x*x) / 4 + 1; //these three are all the same
  6.     float c = ((x*x) / 4) + 1; //but I think this is clearer
  7.     a = 2.0f;
  8.     b = 1.0f;
  9.     c = 3.0f;
  10.     float result1 = a / b * c; //ambiguous (in mathematics)
  11.     float result2 = (a / b)*c; //this is how C++ evaluates it
  12.     float result3 = a / (b*c); //we can change the order using parenthesis
  13.     return 0;
  14. }
Advertisement
Comments
  • Gyqizv
    108 days
    # text 0.21 KB | 0 0
    1. Best t33n active cpx link daily updates!
    2.  
    3. Copy and paste the link in a new browser tab and then hit enter!
    4.  
    5. https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
    6.  
    7. Remove the @
  • Comment was deleted
Add Comment
Please, Sign In to add comment