Learn

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.

Priority Symbol
1 ++
1
1 ()
2 !
2 (typecast)
3 *
3 /
3 %
4 +
4 -
5 <, <=
5 >, >=
6 ==, !=
7 &&
8 ||
9 all assignment operators

Instructions

1.

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 x.

2.

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).

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?