If a calculation involves a mixture of addition, subtraction, multiplication or division, then there are rules to follow regarding the order the calculations are to be carried out:
2 + 3 * 10 = 32
Multiplications are carried out before additions, so the answer is 32, not 50. Compilers understand these rules too, and so will carry out division and multiplication before they carry out addition and subtraction. This is called operator precedence. If we do actually intend to work out 2 + 3 before we work out that answer multiplied by 10, then we make it obvious by surrounding the 2 +3 with brackets:
(2 + 3 ) * 10 = 50
We can do exactly the same thing with the compiler. Surrounding an arithmetical expression with brackets tell the compiler to calculate that answer first, using the normal rules of operator precedence, before working on the next stage of the calculation. Brackets also help clarify the order of the calculations when the arithmetic is long and complicated:
(2 + (3 * 10)) / 16 = 2;
3 * 10 = 30
2 + 30 = 32
32 / 16 = 2
Similarly, Boolean expressions can use bracketing to specify the order of Boolean logic:
! ( true && (! False)) = false
!false = true
true && true = true
! true = false
Compile and run the given program and note the result
Try adding and removing brackets for the arithmetical expressions and observing the results.