1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

comparsion

Discussion in 'C' started by answerme, Jan 19, 2008.

  1. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    main()
    {
    int x=10 ,y=20,z=5 ,i;
    i=x<y<z;
    printf("%d",i);
    }

    output :1
    why the output is 1 ,how x ,y ,z are gettting compared
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Just put a brackets and see how its getting evaluated.

    Check the output for both the cases below
    i=(x<y)<z;
    i=x<(y<z);
     
  3. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    i=x<y<z
    => i= 10<20<z
    => i= true(1) < 5
    => i= true(1)
    => i=1
    This is true If Compiler evaluates from Left to Right if same perority operator are there.
     

Share This Page