{"id":1095,"date":"2022-08-30T15:12:18","date_gmt":"2022-08-30T15:12:18","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/c-pre-post-increment-confusions-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:18","modified_gmt":"2022-08-30T15:12:18","slug":"c-pre-post-increment-confusions-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/c-pre-post-increment-confusions-collection-of-common-programming-errors\/","title":{"rendered":"C# Pre- &amp; Post Increment confusions-Collection of common programming errors"},"content":{"rendered":"<p>Lets have a look at the IL that gets generated from that statement<\/p>\n<pre><code>IL_0002:  ldloc.0     \n<\/code><\/pre>\n<p>Loads the value of x onto the stack. Stack =&gt; (4)<\/p>\n<pre><code>IL_0003:  dup         \n<\/code><\/pre>\n<p>Duplicates the topmost item on the stack. Stack =&gt; (4, 4)<\/p>\n<pre><code>IL_0004:  ldc.i4.1    \n<\/code><\/pre>\n<p>Push 1 onto the stack. Stack =&gt; (1, 4, 4)<\/p>\n<pre><code>IL_0005:  sub         \n<\/code><\/pre>\n<p>Subtract the two top values and push result onto the stack. Stack =&gt; (3, 4)<\/p>\n<pre><code>IL_0006:  stloc.0     \n<\/code><\/pre>\n<p>Store the topmost value of the stack back to x. Stack =&gt; (4)<\/p>\n<pre><code>IL_0007:  ldloc.0     \n<\/code><\/pre>\n<p>Load the value of x back into the stack. Stack =&gt; (3, 4)<\/p>\n<pre><code>IL_0008:  ldc.i4.1    \n<\/code><\/pre>\n<p>Load the value 1 onto the stack. Stack =&gt; (1, 3, 4)<\/p>\n<pre><code>IL_0009:  sub         \n<\/code><\/pre>\n<p>Subtract the two. Stack =&gt; (2, 4)<\/p>\n<pre><code>IL_000A:  dup         \n<\/code><\/pre>\n<p>Duplicate the top value =&gt; (2, 2, 4)<\/p>\n<pre><code>IL_000B:  stloc.0     \n<\/code><\/pre>\n<p>Store the top value back to x. Stack =&gt; (2, 4)<\/p>\n<pre><code>IL_000C:  sub      \n<\/code><\/pre>\n<p>Subtract the two top values. Stack =&gt; (2)<\/p>\n<pre><code>IL_000D:  stloc.0  \n<\/code><\/pre>\n<p>Store this value back into x. <strong>x == 2<\/strong><\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:23:06. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Lets have a look at the IL that gets generated from that statement IL_0002: ldloc.0 Loads the value of x onto the stack. Stack =&gt; (4) IL_0003: dup Duplicates the topmost item on the stack. Stack =&gt; (4, 4) IL_0004: ldc.i4.1 Push 1 onto the stack. Stack =&gt; (1, 4, 4) IL_0005: sub Subtract the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1095","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1095"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1095\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}