This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
priority of operator
- From: Yongming wei <weiyongming2001 at yahoo dot com dot cn>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 1 Jan 2003 19:09:20 -0800 (PST)
- Subject: 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