priority of operator

Yongming wei weiyongming2001@yahoo.com.cn
Thu Jan 2 03:10:00 GMT 2003


This is a problem about priority of operator in c, I
have a simple program:

#include <stdio.h>

main()
{
        int i = 1;
        i = i + ++i;
        printf("%d\n",i);
}

the result is 4 in my redhat 7.3 and 6.2, I think the
compiler first get the result of ++i, because ++ have
high priority than +, so the result is right.

However, after above code is changed to:

#include <stdio.h>

main()
{
        int i = 1;
        i = i + i + ++i;
        printf("%d\n",i);
}

The result is still 4. 

If we write above as: i = ++i + i + i; 
The result will be 6.


Thanks,

Yongming




__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



More information about the Gcc-bugs mailing list