please explain

Discussion in 'C' started by KRV, Jun 1, 2013.

  1. KRV

    KRV New Member

    Joined:
    Dec 26, 2011
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    LEARNING
    Location:
    SRI LANKA
    /* please explain why always get a different out put does print f evaluate from right to left even though there some difference . Is there a procedence for ++a and a++ */
    Code:
    #include <stdio.h>
     int main()
    {
    
        int a = 10;
        a= 10;
        printf("a a++ a ++a a     %d %d %d %d %d\n" , a, a++, a, ++, a);
    
     a= 10;
        printf("a ++a a a++ a     %d %d %d %d %d\n" , a, ++a, a ,a++, a);
    
     a= 10;
        printf("a ++a a ++a a     %d %d %d %d %d\n" , a, ++a, a, ++a, a);
    
     a= 10;
        printf("a a++ a a++ a     %d %d %d %d %d\n" , a, a++ ,a ,a++ ,a);
    
     a= 10;
        printf("a  a++ a     %d %d  %d\n" , a, a++ a);
    
     a= 10;
        printf("a  ++a a     %d %d  %d\n" , a, ++a a);
    
     a= 10;
        printf("a a++ a a++ a a++ a ++a a   %d %d %d %d %d %d %d %d %d\n" \
    , a, a++ ,a ,a++ ,a, a++ , a, ++a, a);
    
    return 0;
    
    }
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    All the compiler is required to do is update the operator at some point in execution; it may occur before the value is printed or after it's printed.

    Here's a great explanation of how the compiler handles it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice