# C++

C++ operators are evaluated from left to right, true or false? explain your answer
###### Who is Participating?

Commented:

EE policy is that homework tasks are not to be completed.  That is, specific questions will receive specific answers (rather like asking a tutor), but general "how do I write this program?" questions will not be answered.  The reason for this is obvious - pointing you in the direction of an operator precedence table (and hopefully an explanation of it in the surrounding pages) will allow you to understand what is going on.  Copying and pasting someone elses words from this site will teach you nothing.  (Didn't mean that to sound as pompous as it did :)
0

Author Commented:
C++ operators are evaluated from left to right, true or false? explain your answer
0

Commented:
sounds like homework.  Look up "operator precedence" in your textbook.
0

Commented:
It depends on which operators you are talking about offcourse. As in math * binds stronger than + so

a+b*c means a+(b*c) rather than (a+b)*c

And then there is also a difference between unary and binary operators : unary operators and assignment operators are right-associative, while all others are left associative, eg. :

a=b=c means a=(b=c)  (assignment)
a+b+c means (a+b)+c  (binary operator +)
*p++ means *(p++) and not (*p)++  (unary dereference operator *)

and so on...

And then there are still some expressions that can't be expressed in terms of precedence or associativity, but are pure grammar rules. The most important one of those is :
"if the statement could possibly be interpreted as a declaration, it is a declaration !!"

eg:
a=b<c?d=e:f=g means a = ((b < c) ? (d = e) : (f = g ))

So actually, you could say that the majority of the C++ operators are evaluated from the left to the right, but this isn't always the case at all.
0

Commented:
C++ operators are not evaluated at all. Expressions are evaluated.
The evaluation order of expressions depends on which type of expression.
Which expression are you referring to?

If in doubt,see the C++ standard, 5 - 'Expressions'

0

Commented:
IainHere,

i guess the other 2 guys are ignoring you and will do his homework anyway!!!!
0

Commented:
0

Commented:
yes, KangaRoo, i stand corrected... you just gave the little Joey a hint. my apologies.
0

Commented:
I think the other response was intended to overwhelm rather than answer.
0

Commented:
and when read that way it's rather funny.
0

Commented:
it depend in the operator:
1) a = b + c

1. the compiler check what is "b + c"
2. the compiler add "b + c" to "a"

2) a * b + c

1. the compiler check what is "a * b"
2. the compiler add "a * b" to "c"

however : the "()" operator can change it.

Exept A++ and ++A !!!

A++ - is always last
++A - is alwase first

example:
A = 1
cout << A++ //OUTPUT : 1
cout << ++A //OUTPUT : 2

0

Commented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

======
Werner
0

Commented:
Folks,

I have gone against the recommendation and accepted IainHere's comment because he issued the warning regarding doing students' homework.

This subject is currently under review by the Moderators, Admin and the site owners; it is certainly academic dishonesty to offer coding as a solution to a problem posed by a teacher, but answering a basic question a student might not understand -- such as this one -- is a little less clear. It's not as if one is answering a question on a test.

Please be very careful if you think you see something that smacks of homework; it is a violation of the Membership Agreement to ask such a question, and is also one to answer it.

Thanks,

Netminder
Community Support Moderator
Experts Exchange

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.