Precedence Rule
<p>I was solving the C++ Multiple choice questions.
I am not able to understand the output for the following code::</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
int main()
{
    int x,y,z;
    x=y=z=1;
    z=++x || ++y &amp;&amp; ++z;
    cout&lt;&lt;x&lt;&lt;" "&lt;&lt;y&lt;&lt;" "&lt;&lt;z&lt;&lt;endl;
    system("pause");
    return 0;
}
</code></pre>

<p>I am solving this question in following way::
Precedence order :: </p>

<pre><code>Precedence "++" greaterthan Precedence "&amp;&amp;" greaterthan  Precedence "||"
</code></pre>

<p>Also , the Associativity of unary++ is "Right to left" 
.
So</p>

<pre><code>z=(++x)||(++y) &amp;&amp; (2)
z=(++x)||(2)&amp;&amp; (2)
z=(2)||(2)&amp;&amp;(2)
z=(2)|| 1  //As 2 &amp;&amp; 2 is 1(true)
z=1       // As 2 || 1 is 1(true)
</code></pre>

<p>So as per me ,the correct output should be x=2,y=2 and z=1.</p>

<p>But When i ran this code in my compiler,the compiler output is x=2,y=1,z=1.</p>

<p>Why i am getting such output and where i am making mistake?</p>

<p>Thanks!</p>
