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

baffling output

Discussion in 'C' started by rahul8590, Aug 28, 2010.

  1. rahul8590

    rahul8590 New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Honeslty have no idea on how is the output being generated ?

    Code:
    
    int main(int argc, char** argv)
    {
            int i=1,j=-1,k=0,l=2,m;  
            m=i++||j++&&k++;  
            printf("%d %d %d %d %d",i,j,k,l,m); 
            return 0;
    }
    
    output : 2 -1 0 2 1 evwn though j++ is is present that value is not being incremented
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    Though evaluation of expression varies from compiler to compiler, but generally it will be from left to right.
    The evaluation of logical operation is done as per truth table, which suggests that for OR operation any one operand yielding to true results the expression to be true.
    So, only first operand of the OR operation was enough for evaluating the result of the expression. The OR and AND operations are having the same priority.
     

Share This Page