<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: can you increment i?</title>
	<atom:link href="http://zengun.org/weblog/archives/2002/11/can-you-increment-i/feed/" rel="self" type="application/rss+xml" />
	<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/</link>
	<description>bloggo ma non troppo</description>
	<lastBuildDate>Fri, 03 Jul 2009 17:06:31 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rahul</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-32980</link>
		<dc:creator>Rahul</dc:creator>
		<pubDate>Fri, 05 Oct 2007 20:07:25 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-32980</guid>
		<description>Hi! I tried the code on C and C++ both, and its same in both cases.
int main()
{
int value,i=1;
value=i + i++ + ++i;
printf(&quot;%d&quot;,value);
i=1;
i += i++ + ++i;
printf(&quot; %d&quot;,i);
return 0;
}

Next i tried it with both volatile and without volatile keyword on &quot;i&quot;. Now the catch is:-
1) Without volatile, i.e. with optimization, the answer is 4 7
2) With Volatile, i.e. without optimization, the answer is 4 5

**Will anybody make it clear why the answer in first part is 7 and in other is 5, what effect does optimization have on this???</description>
		<content:encoded><![CDATA[<p>Hi! I tried the code on C and C++ both, and its same in both cases.<br />
int main()<br />
{<br />
int value,i=1;<br />
value=i + i++ + ++i;<br />
printf(&#8221;%d&#8221;,value);<br />
i=1;<br />
i += i++ + ++i;<br />
printf(&#8221; %d&#8221;,i);<br />
return 0;<br />
}</p>
<p>Next i tried it with both volatile and without volatile keyword on &#8220;i&#8221;. Now the catch is:-<br />
1) Without volatile, i.e. with optimization, the answer is 4 7<br />
2) With Volatile, i.e. without optimization, the answer is 4 5</p>
<p>**Will anybody make it clear why the answer in first part is 7 and in other is 5, what effect does optimization have on this???</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: melz</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10391</link>
		<dc:creator>melz</dc:creator>
		<pubDate>Wed, 29 Jan 2003 22:12:04 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10391</guid>
		<description>Oddly, I guess 6.</description>
		<content:encoded><![CDATA[<p>Oddly, I guess 6.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: blog.tukker.org</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10389</link>
		<dc:creator>blog.tukker.org</dc:creator>
		<pubDate>Mon, 20 Jan 2003 12:26:49 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10389</guid>
		<description>[...] p;#8220;i&#8221;   $i = 1;  $i += ++$i + $i++;  print $i;   For the answer look at the &lt;a href=&quot;http://tidakada.com/archives/p/1942/more/1/c/1&quot;&gt;Original post&lt;/a&gt;  Comments (0) &#124; TrackBack (0) &#124; PingBack (0)          Time for this page: 0.054 [...]</description>
		<content:encoded><![CDATA[<p>[...] p;#8220;i&#8221;   $i = 1;  $i += ++$i + $i++;  print $i;   For the answer look at the <a href="http://tidakada.com/archives/p/1942/more/1/c/1">Original post</a>  Comments (0) | TrackBack (0) | PingBack (0)          Time for this page: 0.054 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Qingy</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10387</link>
		<dc:creator>Qingy</dc:creator>
		<pubDate>Fri, 03 Jan 2003 16:37:23 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10387</guid>
		<description>I guessed 6 :(&lt;br /&gt;
i starts as 1, then it&#039;s added to it&#039;s increment thus 2, but i++; is not counted in the addtion until AFTER the statement, so I got 1 += 2 + 2, thus 5, then the i++ kicks in, giving 6 =\</description>
		<content:encoded><![CDATA[<p>I guessed 6 :(<br />
i starts as 1, then it&#8217;s added to it&#8217;s increment thus 2, but i++; is not counted in the addtion until AFTER the statement, so I got 1 += 2 + 2, thus 5, then the i++ kicks in, giving 6 =\</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Renee Teunissen</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10375</link>
		<dc:creator>Renee Teunissen</dc:creator>
		<pubDate>Mon, 09 Dec 2002 22:29:12 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10375</guid>
		<description>Got 5, as c-code should have given..&lt;br /&gt;
&lt;br /&gt;
Renee.</description>
		<content:encoded><![CDATA[<p>Got 5, as c-code should have given..</p>
<p>Renee.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cessy</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10374</link>
		<dc:creator>Cessy</dc:creator>
		<pubDate>Sat, 07 Dec 2002 01:25:08 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10374</guid>
		<description>Whoa...I&#039;m having a headache. Keep those in the source. &gt;:O</description>
		<content:encoded><![CDATA[<p>Whoa&#8230;I&#8217;m having a headache. Keep those in the source. >:O</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rydain</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10373</link>
		<dc:creator>Rydain</dc:creator>
		<pubDate>Thu, 28 Nov 2002 07:42:43 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10373</guid>
		<description>I quickly guessed 5 and tested it out in C++ (using a plain old int and compiling with g++).  The answer turned out to be 7.  If I think about it some more, it will probably make sense.&lt;br /&gt;
&lt;br /&gt;
/me squirts some WD-40 onto the folds of her brain</description>
		<content:encoded><![CDATA[<p>I quickly guessed 5 and tested it out in C++ (using a plain old int and compiling with g++).  The answer turned out to be 7.  If I think about it some more, it will probably make sense.</p>
<p>/me squirts some WD-40 onto the folds of her brain</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10372</link>
		<dc:creator>Max</dc:creator>
		<pubDate>Fri, 22 Nov 2002 16:53:06 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10372</guid>
		<description>Ah! Oh! 
And I didn&#039;t guessed anything! %-(</description>
		<content:encoded><![CDATA[<p>Ah! Oh!<br />
And I didn&#8217;t guessed anything! %-(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ling</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10369</link>
		<dc:creator>Ling</dc:creator>
		<pubDate>Mon, 18 Nov 2002 23:50:35 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10369</guid>
		<description>i guessed 7 :)</description>
		<content:encoded><![CDATA[<p>i guessed 7 :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christina</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10368</link>
		<dc:creator>Christina</dc:creator>
		<pubDate>Sat, 16 Nov 2002 17:49:31 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10368</guid>
		<description>I guessed 6. ;)</description>
		<content:encoded><![CDATA[<p>I guessed 6. ;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Through</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10366</link>
		<dc:creator>The Through</dc:creator>
		<pubDate>Wed, 13 Nov 2002 14:58:38 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10366</guid>
		<description>It depends on C code optimisations too ;o)&lt;br /&gt;
&lt;br /&gt;
if you compile:&lt;br /&gt;
main() {&lt;br /&gt;
   volatile int i;&lt;br /&gt;
   i = 1;&lt;br /&gt;
   i += ++i + i++;&lt;br /&gt;
   printf(&quot;result: %i\n&quot;, i);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
you&#039;ll see it returns: 3&lt;br /&gt;
and if you consider&lt;br /&gt;
&lt;br /&gt;
   register int i;&lt;br /&gt;
&lt;br /&gt;
it gives: 7</description>
		<content:encoded><![CDATA[<p>It depends on C code optimisations too ;o)</p>
<p>if you compile:<br />
main() {<br />
   volatile int i;<br />
   i = 1;<br />
   i += ++i + i++;<br />
   printf(&#8221;result: %i\n&#8221;, i);<br />
}</p>
<p>you&#8217;ll see it returns: 3<br />
and if you consider</p>
<p>   register int i;</p>
<p>it gives: 7</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: totalementcretin</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10365</link>
		<dc:creator>totalementcretin</dc:creator>
		<pubDate>Mon, 11 Nov 2002 23:03:34 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10365</guid>
		<description>garoo: the problem lies with the pre-incrementation stuff, not the post.</description>
		<content:encoded><![CDATA[<p>garoo: the problem lies with the pre-incrementation stuff, not the post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: garoo</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10364</link>
		<dc:creator>garoo</dc:creator>
		<pubDate>Mon, 11 Nov 2002 17:12:25 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10364</guid>
		<description>That&#039;s the trap, Michel! :))&lt;br /&gt;
&lt;br /&gt;
Try this:&lt;br /&gt;
$i = 1; print ($i + $i++);&lt;br /&gt;
$i = 1; print ($i++ + $i);&lt;br /&gt;
&lt;br /&gt;
If you were right, both lines would give the same result, because the ++ would be interpreted after the print.&lt;br /&gt;
Yet they don&#039;t, because the ++ is interpreted right after the $i++ is evaluated.</description>
		<content:encoded><![CDATA[<p>That&#8217;s the trap, Michel! :))</p>
<p>Try this:<br />
$i = 1; print ($i + $i++);<br />
$i = 1; print ($i++ + $i);</p>
<p>If you were right, both lines would give the same result, because the ++ would be interpreted after the print.<br />
Yet they don&#8217;t, because the ++ is interpreted right after the $i++ is evaluated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RoyalTS - without cheese</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10362</link>
		<dc:creator>RoyalTS - without cheese</dc:creator>
		<pubDate>Sun, 10 Nov 2002 22:02:46 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10362</guid>
		<description>&lt;b&gt;i++, ++i, +=i&lt;/b&gt;&lt;br /&gt;can you increment i?</description>
		<content:encoded><![CDATA[<p><b>i++, ++i, +=i</b><br />can you increment i?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michel v</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10361</link>
		<dc:creator>michel v</dc:creator>
		<pubDate>Sun, 10 Nov 2002 17:28:44 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10361</guid>
		<description>That&#039;s the trap, Garoo! :)&lt;br /&gt;
In fact, 7 is not the result that comes right from the addition. For example if you do &quot;print ($i + ++$i + $i++)&quot;, it will display 6, and then after that statement $i will equal 7.</description>
		<content:encoded><![CDATA[<p>That&#8217;s the trap, Garoo! :)<br />
In fact, 7 is not the result that comes right from the addition. For example if you do &#8220;print ($i + ++$i + $i++)&#8221;, it will display 6, and then after that statement $i will equal 7.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: garoo</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10360</link>
		<dc:creator>garoo</dc:creator>
		<pubDate>Sun, 10 Nov 2002 17:24:55 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10360</guid>
		<description>To me, that&#039;s the way it works:&lt;br /&gt;
&lt;br /&gt;
$i += ++$i + $i++&lt;br /&gt;
[4] [1] [3] [2]&lt;br /&gt;
&lt;br /&gt;
[1] i is incremented =&gt; $i == 2&lt;br /&gt;
[1b] i is evaluated for the addition =&gt; $i += 2 + $i++&lt;br /&gt;
[2] i is evaluated for the addition =&gt; $i += 2 + 2&lt;br /&gt;
[2b] i is incremented right after being evaluated =&gt; $i == 3&lt;br /&gt;
[3] 2 + 2 = 4, so now we have $i += 4, and $i == 3&lt;br /&gt;
[4] 3 + 4 = 7&lt;br /&gt;
&lt;br /&gt;
Ok, it&#039;s not very clearly explained, but I&#039;m late for an appointment, sorry :)</description>
		<content:encoded><![CDATA[<p>To me, that&#8217;s the way it works:</p>
<p>$i += ++$i + $i++<br />
[4] [1] [3] [2]</p>
<p>[1] i is incremented => $i == 2<br />
[1b] i is evaluated for the addition => $i += 2 + $i++<br />
[2] i is evaluated for the addition => $i += 2 + 2<br />
[2b] i is incremented right after being evaluated => $i == 3<br />
[3] 2 + 2 = 4, so now we have $i += 4, and $i == 3<br />
[4] 3 + 4 = 7</p>
<p>Ok, it&#8217;s not very clearly explained, but I&#8217;m late for an appointment, sorry :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michel v</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10359</link>
		<dc:creator>michel v</dc:creator>
		<pubDate>Sun, 10 Nov 2002 16:47:09 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10359</guid>
		<description>Don&#039;t be confused, I may be totally wrong. It all comes down to this question: is the equal sign a sequence stop in PHP? It is not in C, AFAIK.</description>
		<content:encoded><![CDATA[<p>Don&#8217;t be confused, I may be totally wrong. It all comes down to this question: is the equal sign a sequence stop in PHP? It is not in C, AFAIK.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skamp</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10358</link>
		<dc:creator>skamp</dc:creator>
		<pubDate>Sun, 10 Nov 2002 16:45:46 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10358</guid>
		<description>OK, now I&#039;m confused :-/</description>
		<content:encoded><![CDATA[<p>OK, now I&#8217;m confused :-/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skamp</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10357</link>
		<dc:creator>skamp</dc:creator>
		<pubDate>Sun, 10 Nov 2002 16:43:42 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10357</guid>
		<description>OK, a quick reading of PHP&#039;s documentation got me the answer concerning the output in that language.&lt;br /&gt;
In PHP, the expression is evaluated in the following order :&lt;br /&gt;
++$i -&gt; $i = 2&lt;br /&gt;
$i++ -&gt; $i = 3&lt;br /&gt;
$i + $i -&gt; 3 + 3&lt;br /&gt;
$i += -&gt; 1 + 3 + 3&lt;br /&gt;
&lt;br /&gt;
http://docs.skamp.net/php/language.operators.html&lt;br /&gt;
http://docs.skamp.net/php/language.operators.increment.html</description>
		<content:encoded><![CDATA[<p>OK, a quick reading of PHP&#8217;s documentation got me the answer concerning the output in that language.<br />
In PHP, the expression is evaluated in the following order :<br />
++$i -> $i = 2<br />
$i++ -> $i = 3<br />
$i + $i -> 3 + 3<br />
$i += -> 1 + 3 + 3</p>
<p><a href="http://docs.skamp.net/php/language.operators.html" rel="nofollow">http://docs.skamp.net/php/language.operators.html</a><br />
<a href="http://docs.skamp.net/php/language.operators.increment.html" rel="nofollow">http://docs.skamp.net/php/language.operators.increment.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: michel v</title>
		<link>http://zengun.org/weblog/archives/2002/11/can-you-increment-i/comment-page-1/#comment-10356</link>
		<dc:creator>michel v</dc:creator>
		<pubDate>Sun, 10 Nov 2002 16:41:15 +0000</pubDate>
		<guid isPermaLink="false">/?p=1942#comment-10356</guid>
		<description>This is how I see it operated (at least in PHP):&lt;br /&gt;
&lt;br /&gt;
$i +=  ++$i + $i++;&lt;br /&gt;
   [2] [1]    [3]&lt;br /&gt;
&lt;br /&gt;
2 += 2 + 2&lt;br /&gt;
and then $i++, which is executed after the mathematical statement, makes that 6+1 = 7 :)&lt;br /&gt;
&lt;br /&gt;
Your explanation is maybe how Perl works with that line.</description>
		<content:encoded><![CDATA[<p>This is how I see it operated (at least in PHP):</p>
<p>$i +=  ++$i + $i++;<br />
   [2] [1]    [3]</p>
<p>2 += 2 + 2<br />
and then $i++, which is executed after the mathematical statement, makes that 6+1 = 7 :)</p>
<p>Your explanation is maybe how Perl works with that line.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

