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 - 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
-
-
-
-
-
Working with math operators3m 13s
-
(Locked)
Challenge: Do some math50s
-
(Locked)
Solution: Do some math1m 47s
-
(Locked)
Using assignment operators1m 49s
-
(Locked)
Obeying the order of precedence3m 14s
-
(Locked)
Challenge: Get the order correct55s
-
(Locked)
Solution: Get the order correct1m 37s
-
(Locked)
Working with relational operators3m 48s
-
(Locked)
Using logical operators3m 58s
-
(Locked)
Understanding bitwise operators3m 44s
-
(Locked)
Shifting bits3m 13s
-
(Locked)
Exploring unary operators3m 3s
-
Chapter challenge: More math1m 8s
-
(Locked)
Chapter solution: More math2m 45s
-
-
-
-
-
-
-
-
-