M
Mark Hobley
The following statement gives a result of 10, which is what I expect, because
multiplication has a higher precedence than addition:
print 4 + 2 * 3; # 10
I now add brackets to change the precedence:
print (4 + 2) * 3; # This unexpectedly gives 6
Reversing the calculation:
print 3 * (4 + 2); # This gives 18, as expected
Why do I get the answer 6 to (4 + 2) * 3?
--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE
Telephone: (0121) 247 1596
International: 0044 121 247 1596
Email: markhobley at hotpop dot donottypethisbit com
http://markhobley.yi.org/
multiplication has a higher precedence than addition:
print 4 + 2 * 3; # 10
I now add brackets to change the precedence:
print (4 + 2) * 3; # This unexpectedly gives 6
Reversing the calculation:
print 3 * (4 + 2); # This gives 18, as expected
Why do I get the answer 6 to (4 + 2) * 3?
--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE
Telephone: (0121) 247 1596
International: 0044 121 247 1596
Email: markhobley at hotpop dot donottypethisbit com
http://markhobley.yi.org/