讨论个问题..
unsigned int a=5;int b=-7; 改为-3 在试试...
(a+b>5)?puts(">5"):puts("<=5");
[此贴子已经被作者于2007-5-29 21:01:50编辑过]
[此贴子已经被作者于2007-5-29 21:01:50编辑过]
2007-05-29 20:43
#include<stdio.h>
#include<conio.h>
int main()
{
unsigned int a=5;
int b=-7;
((int)a+b>5)?puts(">5"):puts("<=5");
getch();
return 0;
}
你运行这个试试
类型问题

2007-05-29 20:56

2007-05-29 21:16
2007-05-29 21:34
2007-05-29 21:50
为了证明我的正确结论,我试了不同的编译器,结果都一样,难道都有BUG?于是又做了
#include<stdio.h>
#include<conio.h>
int main()
{
unsigned int a=5, b=-7;
(a+b)>a?puts(">5"):puts("<=5");
getch();
return 0;
}或b=-3;结果是同上没改的结果一样,说明unsigned int 比较大小有问题~

2007-05-29 22:01
2007-05-29 22:06
2007-05-29 22:09
有结果了int -7先转化为unsigned int (65535-7+1) a+b=65534 int -3先转化为unsigned int (65535-3+1) a+b=2所以楼主你结果就这样得出

2007-05-29 22:18
最基本的东西都忘了...

2007-05-29 22:25