This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

priority of operator


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]