C does not just process the statements you send it blindly from left to right. It looks at the statements and applies standard rules to the order in which the statements should be processed. For instance, it will do multiplication before addition.
There are many more symbols and operations you will learn as you progress with your knowledge of C, but here is a list of the order for the operations we have gone over in this lesson. The higher priority operations will be performed before lower ones.
|9||all assignment operators|
The code on the right is using the order of operations described above, so for the variable
x it will do the multiplication first then the addition. However, we want the addition to occur first.
Please fix the line of code to tell the compiler to do the addition first for evaluating into
Now take a look at the
y equation and notice that it will do the division first, and as an
int it will cast it to 0, then add 6. Update the line so it does the addition first and resolves to 0 (casting to an int).