From the course: Advanced C Programming: Optimize Performance and Efficiency
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: Advanced C Programming: Optimize Performance and Efficiency
Obeying the order of precedence
- [Instructor] You can call it a pecking order, and you've probably seen examples in various bits of code as well as in other movies in this course, but it's the order of precedence. It determines which operations take place first in a complex equation or expression. Open exercise file 05-08_order1. Here you see an equation at line 7. You can do the math in your head but will you get the same answer as the computer? So 5 plus 20 is 25, times 2 is 50, minus 8 is 42, divided by 2 is 21. So is the answer 21? Build and run the code. The computer generates 41 as the answer. The reason is simple. Certain operators have priority or precedence over others. In this case, if you look at line 7, multiplication and division have precedence over addition and subtraction. So 20 times 2 is 40, and 8 divided by 2 is 4 5 plus 40 is 45, minus 4 is 41. That's how the equation was evaluated in the C language. Obviously, knowing…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
When to use the ampersand operator4m 20s
-
(Locked)
How to bind the asterisk operator4m 51s
-
(Locked)
Challenge: Incrementing a pointer23s
-
(Locked)
Solution: Incrementing a pointer1m 10s
-
(Locked)
Understanding arrays and pointers4m 4s
-
(Locked)
Challenge: Displaying an array29s
-
(Locked)
Solution: Displaying an array54s
-
(Locked)
Obeying the order of precedence6m 27s
-
(Locked)
-