C语言5.0

c语言学习当中,如有偏颇之处,还望见谅;
讲一个有意思的题;

int main()
{
int a=12;
a+=a=a/=a-6;
printf("%d",a);
return 0;
}
答案是:8
因为在C语言中,+,-, 的优先级高于+=,
=,/=,所以先进行加减的算法,假设 t1=a-6=12-6=6,然后进行同级运算,t2=a/t1=12/6=2,t2=a=2,t3=at2=22=4;
t3=a,t4=t3+a=8;
挺有意思的,是吧;简单的说就是;a+=2,a=a+2;

再举一个例子;
int main()
{
long iLong;
short iShort;
int iNumber=10;
int iNumber=20;
char cChar[10];
printf('Enter the long integer:\n);
scanf("%ld',&iLong);
printf("Enter the short integer:\n);
scanf("%hd",&iShort);
printf("Enter the number:\n");
scanf("%d*%d",&iNumber,&iNumber);
printf("Enter the string but only three character:\n);
scanf("%3s",&cChar);
printf("the long is %ld\n",iLong);
printf("the short is %hd",iShort);
printf("the number1 is %d\n",iNumber1);
printf("the number2 is %d|n“,iNumber2);
printf("the three characer is %s\n",cChar);
return 0;
}
如有出错,还望见谅;

猜你喜欢

转载自blog.51cto.com/15098536/2621171
今日推荐