Nischal
Nischal

Reputation: 11

c++ order of preference.. how is this expression evaluated?

I am trying to understand code of some library of one simulation tool that i use.. It has the following line:

propData->fadingStretchingFactor =
        (double)(propProfile0->samplingRate) *
        propProfile->dopplerFrequency /
        propProfile0->baseDopplerFrequency /
        (double)SECOND;

Now how do u figure out the order of operations if there are two consecutive division operators as in this example

Upvotes: 1

Views: 342

Answers (3)

Nick
Nick

Reputation: 3156

Left to right associativity

http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence

Upvotes: 0

ephemient
ephemient

Reputation: 204828

Division is left associative. a / b / c is equivalent to (a / b) / c.

Note that C (and C++) do not guarantee any ordering between the evaluations of the terms a, b, and c. For example, foo() / bar() could call foo() before bar() or foo() after bar().

Upvotes: 6

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272557

The grouping of operations of equal precedence is determined by operator associativity.

In C++, division is left-associative, which means that the leftmost operation is grouped first, i.e.:

a / b / c

is the same as:

(a / b) / c

Upvotes: 4

Related Questions