++ ,--以及printf里的一些问题
#include <stdio.h>
int main(){
int i=3,j=3,k=0,m=3,n=0,l=3,a=5,b=5;
k=(j++)*(++j)+(j--)*(--j);
n=(l++)+(l++)+(l++);
printf("k=%d (i++)*(++i)+(i--)*(--i)=%d (m++)+(m++)+(m++)=%d n=%d\n",k,(i++)*(++i)+(i--)*(--i),(m++)+(m++)+(m++),n);
a=(a--)+3;
printf("a=%d b=%d (b=(b--)+3)=%d b=%d\n",a,b,b=(b--)+3,b);
printf("i=%d j=%d l=%d",i,j,l);
}
为什么k跟printf里的(i++)*(++i)+(i--)*(--i)值不同
为什么a=(a--)+3结果为7
以及为什么printf("a=%d b=%d (b=(b--)+3)=%d b=%d\n",a,b,b=(b--)+3,b);最后结果为7,8,8,5
谢谢了
又见++贴.你可搜一下,在C版中就有N多
http://community.Codefund.cn/Expert/topic/5161/5161529.xml?temp=.2859613
http://community.Codefund.cn/Expert/topic/5090/5090550.xml?temp=.1131098
http://community.Codefund.cn/Expert/topic/5090/5090550.xml?temp=.1131098
http://community.Codefund.cn/Expert/topic/5050/5050739.xml?temp=.5225641
http://community.Codefund.cn/Expert/topic/5051/5051593.xml?temp=.6827509
http://community.Codefund.cn/Expert/topic/5003/5003337.xml?temp=.9408075
http://community.Codefund.cn/Expert/topic/4983/4983657.xml?temp=2.363223E-02
http://community.Codefund.cn/Expert/topic/4967/4967105.xml?temp=.2996637
...
这个与编译器有关,讨论这种问题实在没多大意义
keiy at 2007-10-19 >
