Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>++</code> operator increments the pointer value, but then returns the original value ... so <code>print(s++)</code> will print the value of <code>s</code> before the increment, since even though it adds a value of 1 to <code>s</code>, making the value stored at <code>s</code> equal to <code>s+1</code>, it still <em>returns</em> the original value of <code>s</code> as the <em>result</em> of the operation. On the otherhand <code>print(s+1)</code> prints the value after the increment, but very importantly does not modify the original value of <code>s</code>. So the <em>result</em> of the statement <code>s+1</code> is just a new temporary pointer value ... the original value of <code>s</code> is not modified.</p> <p>Furthermore, since you've incremented and changed the value of <code>s</code> with the <code>++</code> operator, when you call <code>cout</code>, you're now printing the value to wherever the new pointer is pointing (this could cause a crash or segmentation fault if you're not careful and there's no user accessible memory at the new memory location <code>s</code> is pointing to). With <code>s+1</code>, the value of <code>s</code> remains unmodified, so the result of <code>cout</code> will be to wherever <code>s</code> was originally pointing.</p> <hr> <h2>Edit:</h2> <p>As Michael points out, this is actually a recursive function, so the second example simply keeps calling <code>print()</code> with the same argument, since as mentioned before, the returned value from <code>s++</code> is the original value of <code>s</code>. That means you'll end up with a stack overflow at some point and just crash unless the value that <code>s</code> pointed to was already the NULL character.</p>
    singulars
    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. 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