<div dir="ltr">You are using the value that you are incrementing in the same sequence point. C and C++ does not define whether (a < a++) is the same as a < a, a++, or a++, a < a, or some other variation on that theme (and no, it doesn't help if you do (a < b++ || b < a++), it's still undefined what order the ++ and greater than happens in. <br><br>It is only OK if you do them separately, in different sequence points (if sequence point is a mystery to you, google it, as my explanation will not be as good as what you find in google). The only thing that IS defined is that a is one more AFTER the sequence point. <br><br>This is just one example of such undefined behaviour. Both C and C++ are languages that have a lot of "undefined behaviour", where it is up to the implementor of the compiler and the hardware exactly what happens (including completely unexpected behaviour, such as the compiler starts a game, turning off the power, rebooting or the generated code crashes for things that you don't expect to crash). Included in "undefined behaviour" is "it works as you expect", but it also covers everything else that computer is capable of possibly doing. [Of course, compiler people are typically kind (or at least not evil) and try their best effort to make the undefined behaviour as "nice" and close to what you would expect as possibly can, as long as it doesn't harm performance for defined behaviour]<div><br></div><div>--</div><div>Mats<br><div><br></div><div>--</div><div>Mats</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 23 May 2015 at 22:29, umang777bhatt <span dir="ltr"><<a href="mailto:umang777bhatt@gmail.com" target="_blank">umang777bhatt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">int main()<br>
{<br>
int a=012;<br>
int b=05;<br>
if(a<++a||b<++b)<br>
printf("DJ");<br>
else<br>
printf("%d Welcome %d",a,b);<br>
}<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__clang-2Ddevelopers.42468.n3.nabble.com_Undefine-2Dbehaviour-2DCan-2Done-2Dexplain-2Dme-2Dthis-2Dcode-2Dtp4045706.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=CnzuN65ENJ1H9py9XLiRvC_UQz6u3oG6GUNn7_wosSM&m=0hQ4WgJOMcDgvkZm5fC8T-82-3ox1ryEHEhfqDK_T7U&s=cKvhdkm2Ks7w0Od-uly3zDzsUGX9o4dKSSsHJZ-VXLk&e=" target="_blank">http://clang-developers.42468.n3.nabble.com/Undefine-behaviour-Can-one-explain-me-this-code-tp4045706.html</a><br>
Sent from the Clang Developers mailing list archive at Nabble.com.<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>