Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to <a href="http://en.cppreference.com/w/cpp/language/operator_precedence" rel="nofollow">C++ Operator Precedence</a>:</p> <ol> <li><p>"*" has the same precedence as <em>prefix</em> "++" but must be avaluated <strong>rigth to left</strong>.</p> <p>printf("%s ", ++*p);</p></li> </ol> <p>So first <code>*p</code> is evaluated, then <code>++(*p)</code>, leading to the second character in the first string.</p> <ol> <li><p>"*" has <strong>less</strong> precedence than <em>suffix</em> "++".</p> <p>printf("%s ", *p++);</p></li> </ol> <p>So first <code>p</code> is incremented, <strong>but</strong> it is a <em>post-increment</em>. The value returned from the operation <em>is the original one</em>. This way, the <code>*</code> operates over the original pointer, that pointed to the second char on the first string.</p> <p>Note that, this time, <code>++</code> is operating over <code>p</code>, and not over <code>*p</code>.</p> <ol> <li><p>Since "2", <code>p</code> points to the second string. When you do <code>++*p</code> you are now pointing to the second character of the second string ("s"). As you are again using a <em>pre-increment</em>, the value passed to <code>printf</code> is already changed.</p> <p>printf("%s ", ++*p);</p></li> </ol> <p>I may get clearer if you do a little change and print the pointer value aswell (ignore the warnings):</p> <pre><code>printf("%s [%p]\n", ++*p, p ); printf("%s [%p]\n ", *p++, p ); printf("%s [%p]\n ", ++*p, p ); nowledge [0x7fff6f5519e0] nowledge [0x7fff6f5519e8] s [0x7fff6f5519e8] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload