- int main()
- {
- int x,y,z;
- x=y=z=1;
- ++x||++y&&++z;
- printf(“%d\t%d\t%d\n”,x,y,z);
- return 0;
- }
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
c first of all compiler will check the or operator as it has more priority than and gate then now in this case…it will execute from left
1st process x=1
then as soon as itll obtain or operator it ll incremt its value and then if it iz >0 it will directly give answr as 1…
thanx
c first of all compiler will check the or operator as it has more priority than and gate then now in this case…it will execute from left
1st process x=1
then as soon as itll obtain or operator it ll incremt its value and then if it iz >0 it will directly give answr as 1… for the whole expression……….
but for x=2,y=1,z=1
thanx
im sorry actually i dint see properly…..
actually x will incremented before encountering || operator………
thnx
++x||++y&&++z
x gets preincremented to 2.
since logical or is evaluating to true in first expression(i.e. ++x) so rest of expression is not evaluated.
and the result is 2,1,1
x=y=z=1;
++x (pre increement) it means x will be 2
here ||(logical or)
according to the compiler..it wont check further it it is true..so there will be no change in the values of y and z
your output will be 2,1,1
for instance…
x=-1,y=1,z=1;
then x,y,z will be 0,2,2
logical or(||) -> if the first statement is true(1) then it wont check it further
whereas logical(&&)–>it checks the whole statement.. here priority of these operators doesn’t matter..it goes from left to right