6
我已经在无符号变量中分配了补码值。为什么这个C程序输出一个负数?
那么为什么这个C程序输出一个负数呢?
#include<stdio.h>
#include<conio.h>
int main()
{
unsigned int Value = 4; /* 4 = 0000 0000 0000 0100 */
unsigned int result = 0;
result = ~ Value; /* -5 = 1111 1111 1111 1011 */
printf("result = %d", result); /* -5 */
getch();
return 0;
}
您的问题应该是:“编译此代码时,为什么编译器不会发出警告?”。答案是:“打开编译器的警告(例如-Wall)” – 2010-05-02 09:59:30