Vladyslav Klymchuk
Vladyslav Klymchuk

Reputation: 11

During less than or equal to comparison what comparison is evaluated first?

When we have simple condition (a<=b), what is actually happening? Will it firstly compare a<b, and if it's false will compare a==b (a<b || a==b)?

Upvotes: 0

Views: 66

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 222753

a <= b evaluates to true (1) if and only if a is less than or equal to b. In typical C implementations, this determination is performed via a single machine instruction. If, for some reason, multiple instructions are needed, the C standard does not specify any ordering for them, just that the result is correct.

If a and b are expressions beyond simple identifiers, the C standard does not specify any ordering for evaluation of them, their parts, or their side effects due to the <= operator, although there may be ordering constraints within the expressions.

Upvotes: 1

Related Questions