From the course: Complete Guide to C Programming Foundations

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Obeying the order of precedence

Obeying the order of precedence - C Tutorial

From the course: Complete Guide to C Programming Foundations

Obeying the order of precedence

- [Instructor] You've seen puzzles like this on social media. What is the result of this equation? People have different answers, and quarrels erupt over who is accurate. One answer is correct, and you'll know it when you understand the order of precedence. Here is the order for mathematical operations in the C language and in math itself. Work the equation left to right. If the equation contains any expression in parentheses, calculate it first. Outside of parentheses, perform multiplication and division, moving left to right, then perform addition and subtraction, moving left to right. Not only do these rules help you dominate social media; they help you to construct proper expressions in your C code as well. This code contains that same infamous internet puzzle shown earlier. Run the program to see who's right and who's wrong. Mystery solved. Working left to right here on line seven, six divided by two is three, multiplied by the result of one plus two, or three again. Three times…

Contents