post and pre increment in c

Posted by jammkie same on Stack Overflow See other posts from Stack Overflow or by jammkie same
Published on 2010-05-25T07:03:22Z Indexed on 2010/05/25 7:11 UTC
Read the original article Hit count: 211

Filed under:
|
void main()  
{  
    int a=2 , c;  
    c=a++ + ++a + ++a + ++a;  
    printf("%d",c);  
}

prints 20, whereas

void main()  
{  
    int a=2;  
    int c=a++ + ++a + ++a + ++a;  
    printf("%d",c);  
}  

prints 17.

Can someone explain the reason for this.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c