Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the value of a=10; a=a+++ 1

Status
Not open for further replies.

Krisan

Programmer
Dec 28, 2000
1
0
0
IN
What is the value of
a=10;
a=a+++a+++a++;
mail to smk_in@rediffmail.com
 
it is 33.
a=33 after the statement...
all r post increments.. so the lvalue returned is (10+10+10) and then u do the post increments thrice to get the new value of a=30+1+1+1=33!

hth,
shail.
 
Actually, the result is undefined.

It has to do with the fact that you're modifying the same object more than once within a single expression. If you do this, the result is undefined by the C standard. This means unpredictable results as implementations aren't bound by anything in the standard as to how they should handle situations like the above (or even if they should handle it at all -- i.e. terminate the program instead).

So, all bets are off and expressions like this one can and will produce different results across implementations.

For a more detailed explanation, here are some links to relevant sections of the comp.lang.c FAQ:


Also, IIII, members prefer to answer people in the forums. This way, members who prefer to keep their identity private they can actively participate. For other members it is a benefit because now anyone with this problem now has a resource and an answer. For you, it keeps recruiters and salespeople from grabbing your e-mail address and spamming, and also keeps them away from these forums.

As we all know, one of the main tricks of salespeople and recruiters is to "pose" as technical people in forums asking technical questions. Than, when the responses come in they start spamming us. These forums pretty much cut them all off! I'm not saying you are a recruiter, just that this is how they work.

Members of these forums who join can also mark any thread with the "notify me" feature and are notified via e-mail when threads are responded to. It's pretty slick. :)

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top