Public Group

# Order Of Operation

This topic is 4101 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Do C# and C++ dollow the same order of operation as Algebra does or is it different?

##### Share on other sites
Click there
Scroll down to the bottom and look at the chart. Going by algebraic order is a safe assumption [wink]

##### Share on other sites
Cool I like that article. I never thought of all the other operators having a certain order. Thanks a lot.

##### Share on other sites
Semantic nitpick: This is operator precedence, not order of operation.

In the C++ expression:
a()*b() + c()*d()

This means that this is equivalent to:
(a()*b()) + (c()*d())

Rather than, say:
a() * (b()+c()) * d()

However, the calls a(), b(), c(), and d() could occur in any order. The only guarantees the C++ standard makes are:

1) a() and b() will have been evaluated when operator*(a_result,b_result) is evaluated
2) c() and d() will have been evaluated when operator*(c_result,d_result) is evaluated
3) operator*(a_result,b_result) and operator*(c_result,d_result) will have been evaluated when operator+(ab_result,cd_result) is evaluated.

Similarly, the left-to-right associative precedence of most arithmetic operators only means that:
a()-b()-c()

Is equivilant to:
(a()-b())-c()

Rather than:
a()-(b()-c())

Rather than specifying an order in which a(), b(), and c() would be evaluated in.

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633742
• Total Posts
3013630
×