C# C# Basics (Retired) Perform Order of Operations

Sreeni Gajapathy
Sreeni Gajapathy
941 Points

is 8*7+8%5+6/2 same as (8*7)+(8%5)+(6/2)?

I end up with 60 for the below expression. Please advise where I'm doing it wrong.

Expression: 8*7+8%5+6/2

My thoughts: we have *, %, /, + so with order of precedence (left to right), I do this: 56 + 1 + 3 = 60.

2 Answers

Steven Parker
Steven Parker
171,342 Points

It looks like you understand the operator precedence correctly .. that's most of it!

But 8 % 5 does not equal 1.

The "%" symbol is the modulus or remainder operator. It gives you what would be left over after a divide. So, for example, 12 % 10 would be 2.

Sreeni Gajapathy
Sreeni Gajapathy
941 Points

Thanks Steven! That's so silly of me to assume it to be dividend.