4 / 3 * 2 ??? I thought this would be 4 / (3 * 2)? But it evaluates to (4 / 3) * 2
-brian
Main Topics
Browse All TopicsAre this correct? And can you provide me with more examples of precedence regarding:
Parentheses (grouping)
Pre (increment/decrement)
Unary plus/minus
Unary logical negation Unary
Multiplication/division/mo
Addition/subtraction
Relational less than/less than or equal to
Relational greater than/greater than or equal to
Relational is equal to/is not equal to
Bitwise AND
Bitwise exclusive OR
Bitwise inclusive OR
Logical AND
Logical OR
Ternary conditional
i || j || k -> ( i || j ) || k
i && j || k -> (i && j) || k
i || j && k -> i || (j && k)
i || ++j -> i || (j = j + 1)
when you use an assignment statment in a expression whats the precedence?
c || (j = k = 2), is this just c || 2???
-brian
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi BrianGEFF719,
The C grammar precedence is laid out here:
http://www.difranco.net/co
Good Luck!
Kent
Hi BrianGEFF719,
> those produce the same result, but I thought that division had higher
> precedence than mod, and multiplication had higher precedence than division.
Again, check the table mentioned above. Multiplication, division, and modulo are equally weighted. They're evaluated left to right.
Kent
Hi BrianGEFF719,
> i || j || k -> ( i || j ) || k // logical or evaluates left-to-right. These are equivalent
> i && j || k -> (i && j) || k // logical and is higher precedent than logical or. These are equivalent
> i || j && k -> i || (j && k) // logical and is higher precedent than logical or. These are equivalent
> i || ++j -> i || (j = j + 1) // unary preincrement is higher precentent that logical or. These are equivalent.
You get an 'A'. (Assuming of course that you were using -> as a separator, not an embedded dereference. :) )
Kent
Hi BrianGEFF719,
Yes. There are hardware reasons behind some of this.
1) On machines so equipped, ++j uses the INCR or increment instruction. Basically, the opcode instructs the CPU to add 1 to the value at the specified address.
2) j = j+1 is handled by the expression evaluator. J+1 is evaluated, and the result stored back at J.
Kent
Business Accounts
Answer for Membership
by: BrianGEFF719Posted on 2005-03-02 at 18:00:53ID: 13446065
I'm trying to make study sheets for this stuff...So any suggestions you guys got would be appricated.