EmbLogic's Blog

problem in assingment 01

  1. int main()
  2. {
  3.     int x,y,z;
  4.     x=y=z=1;
  5.      ++x||++y&&++z;
  6.      printf(“%d\t%d\t%d\n”,x,y,z);
  7.      return 0;
  8. }

5 Responses to problem in assingment 01

  1. himanshi says:

    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

  2. himanshi says:

    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

  3. himanshi says:

    im sorry actually i dint see properly…..
    actually x will incremented before encountering || operator………

    thnx

  4. ++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

  5. hemant.kumar says:

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>