#include <stdio.h>
int main(int argc, char* argv[]) {
unsigned char c = 10;
unsigned short d = 10;
unsigned int e = 10;
unsigned long f = 10;
double g = -c;
double h = -d;
double i = -e;
double j = -f;
printf("%d %lf\n", c, g);
printf("%u %lf\n", d, h);
printf("%u %lf\n", e, i);
printf("%lu %lf\n", f, j);
}
输出结果
10 -10.000000
10 -10.000000
10 4294967286.000000
10 18446744073709551616.000000
为什么结果不一致,有些类型得到-10,而其他类型得到巨大的值?
int
);对于后两个,只需将一元负号应用于无符号类型。 - dyp