Jun 122012

If the initial value of i is 2 What is the value of expression i++ + i++?


It’s undefined. Both in C & in C++.

The standard says:

“If you read a variable twice in an expression where you also write it, the result is undefined.”

So you should never do that 🙂

Another example is:

arr[i] = i++;

More undefined behavior: In the below example also, the values passed to the function are not defined irrespective to the value of i.

fun(arr[i], i++);

Here, the result is undefined because the order of evaluation of function arguments is undefined



 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>