Des*_*tor 4 c implicit-conversion
我看到下面的代码打印输出"相同"但我在理解这个程序时遇到了麻烦.请帮我理解这个程序.
int main()
{
unsigned int x = -1;
int y = ~0;
if(x == y)
printf("same");
else
printf("not same");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出"相同"如何来?请帮我看看这里发生了什么.
Mic*_*CMS 10
无符号整数x = -1有位标志(32位):
11111111111111111111111111111111
Run Code Online (Sandbox Code Playgroud)
int 0有位标志(32位):
00000000000000000000000000000000
Run Code Online (Sandbox Code Playgroud)
〜0是0(按位)的否定,即(32位):
11111111111111111111111111111111
Run Code Online (Sandbox Code Playgroud)
作为旁注:
unsigned int x = -1;
Run Code Online (Sandbox Code Playgroud)
相当于
unsigned int x = UINT_MAX.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |