undefined behaviour

  • Thread starter subramanian100in
  • Start date
S

subramanian100in

Suppose

int i = 2;

i = ++i + 1;

Please explain whether the evaluation of this statement, has undefined
behaviour ?
 
S

santosh

Suppose

int i = 2;

i = ++i + 1;

Please explain whether the evaluation of this statement, has undefined
behaviour ?

Yes, you're modifying an object twice without an intervening sequence
point. In such cases, the order of evaluation of the expression is
undefined by the standard, though a particular implementation might
happen to produce results that you might consider appropriate.
 
S

santosh

Suppose

int i = 2;

i = ++i + 1;

Please explain whether the evaluation of this statement, has undefined
behaviour ?

In case you don't know yet, this group has a very useful FAQ at
http://www.c-faq.com/

It'll help you avoid asking questions, like this one, that've been
beaten to death over the years here.
 
S

Sharath

Suppose

int i = 2;

i = ++i + 1;

Please explain whether the evaluation of this statement, has undefined
behaviour ?

Yes, it does have undefined behavior. Because the value of 'i' is
modified more than once between sequence points.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top