Binary operators convert the smaller(less precise) operand to the type of the larger(more precise) operand. All operators will convert things smaller than ints to ints or larger. This includes char 's! 1.byte,char,short默认转成int 2.byte->short->int->long->float->double char^
All operators will convert things smaller than ints to ints or larger. This includes char 's!
1.byte,char,short默认转成int
2.byte->short->int->long->float->double
char^
是这样的吗?
一个就是给CHAR类型赋值,一个是将一个INT类型的赋给char类型的
char 是属于byte型的,97是在byte的范围内,所以char a=97
97是在byte的范围内,系统就认为这个97是byte,就没什么错了,但是你假如int i=97;
再char a = i;的话,系统肯定会报错的,原因如上的转换方向所示还有假如你的 char a =xxx,这个xxx超过byte的范围的话,系统也会报错的
如char a = 32767,肯定报错,
所以楼主的那个 char a = 'a'+2;属于第二种情况