ulfben icon

Operator precedence

ulfben | PRO | 09/04/17 08:41:12 PM UTC | 0 ⭐ | 908 👁️ | Never ⏰ | []
C++ |

460 B

|

None

|

0 👍

/

0 👎

//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;
}

Comments

  • Gyqizv icon
    04/02/26 06:13:58 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎