#include<stdio.h> int main() { char a = 100; char b = 200; char c = a+b; printf("%d %d ",c,a+b); //printf("%d ",b); unsigned char x = 100; unsigned char y = 200; unsigned char z = a+b; printf("%d %d ",z,x+y); //printf("%d ",y); return 0; }
运行结果:
由于是char类型其范围是 -128~127,char b = 200;超出其范围,就变成了成了负数-56,所以输出就变成了44,然而第二个是无符号的char类型,其范围是0~255,所以y的值么有超出范围,所以z还是输出44,由于是%d输出,x+y 就被转成了更高级的int型输出,并且x,y 赋值是合法的,也么有超出范围,所以输出就是300.
(个人见解,有待完善)