Simple calculations
No. 2
Working with variables
Q: |
This exercise is about two variables
|
||||||||
A: |
A naive solution reads:
This unfortunately does not work. The above expression is being evaluated from left to right thus being fully equivalent to:
As we shall see in the section called “Operators and expressions” each of these constituents evaluates to a string thus producing: -4+100=-4100 Adding a pair of braces grouping
This is equivalent to:
Reverting to the original variable values 4 and 7 still yields a correct output:
|