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.

Looking at the table below, the operations with priority 1 will be performed first. Then priority 2, 3, and so on will be processed. For operators of the same level of priority, they operations occur from left to right.

Priority Symbol
1 ++
1 --
1 ()
2 !
2 (typecast)
3 *
3 /
3 %
4 +
4 -
5 <, <=
5 >, >=
6 ==, !=
7 &&
8 ||
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 x.


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.

Or sign up using:

Already have an account?