Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li>The <code>&amp;</code> operator, like the <code>*</code> operator<sup>1</sup> can be used for two different things depending on whether it's used as a <em>binary</em> or <em>unary</em> operator. <ol> <li>Unary <code>&amp;</code> like <code>&amp;var</code> takes the address of <code>var</code>. This is necessary to pass it to <code>scanf</code>.</li> <li>Binary <code>&amp;</code> like <code>var &amp; var</code> is a bitwise AND, like item #2. <ul> <li>Notice that the spacing doesn't matter. What does matter is if there's operands on both sides of the <code>&amp;</code>. So <code>&amp; var</code> is still unary <code>&amp;</code> and <code>var &amp;var</code> is still binary <code>&amp;</code>.</li> </ul></li> </ol></li> <li><code>(x&amp;x-1)</code> is doing a bitwise AND with <code>x</code> and <code>x-1</code>.</li> <li><code>(x|x-1)</code> is doing a bitwise OR with <code>x</code> and <code>x-1</code>.</li> <li>Yes <code>%</code> means modulus.</li> <li><code>1 &lt;&lt; n</code> is doing a bitwise shift of 1 to the left <code>n</code> digits</li> <li>the <code>%i</code> you are seeing as the first argument to <code>printf</code> are format symbols to which specify that the next argument is an <code>int</code>, so that <code>printf</code> can print it properly (because it doesn't know what type it is by itself, so you have to tell it). It has nothing to do with modulus. You can see a very in-depth definition of <code>printf</code> here: <a href="http://pubs.opengroup.org/onlinepubs/9699919799/" rel="nofollow">http://pubs.opengroup.org/onlinepubs/9699919799/</a> (thanks pmg) <ul> <li>If <code>%i</code> were outside a string, it would be to the left of some other operand, and mean modulus.</li> <li><code>%i</code> in a string doesn't mean anything by itself. It only means something to <code>printf</code> because <code>printf</code> treats it specially. It searches the string it gets for occurrences of <code>%format</code> (where <code>format</code> is a format, not the word "format") and does something depending on what format it encounters.</li> </ul></li> </ol> <p><sup>1</sup> The <code>*</code> operator also has two different versions: a unary version and a binary version. The unary version means pointer indirection, and the binary version means multiplication.</p>
 

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