标签:
int a = 10.8; // double 自动转换成int,会有警告;
int a = (int)10.8; // double 自动转换成int,不会再有警告;
double c = 10.6 + 6; // 会将6自动提升为double进行加法运算;
a += 5; // a = a + 5;
a *= 6; // a = a * 6;
a += 5 + 6 + 4; // a = a + (5 + 6 + 4);
如:int result = 2 > 3 == 1;
解析:先运算: 2 > 3 返回0,假
再运算: 0 == 1; 返回为0,假
即结果:result = 0;
如:int result = 4 > 3 > 2;
结果: result = 1 > 2 = 0;
如:int result = 3 + 4 > 8 - 2;
解析:int result = 7 > 6;
即结果:result = 1;
如:
int a = 10;
int b = 10;
int c = (a < 5) && (++b >= 11);
结果:a = 10, b = 10, c = 0;
解析:当运算完 a < 5 后,即为0,就会决定c = 0;将不再运行b >= 11, 即,没有进行 ++b,导致 b = 10。
如:int c = 5 && 6;
如:int a = !!5; 结果:a = 1;
4.代码练习:
结果:
如:int a = 10 > 5 ? 9 : 6;
结果:a = 9;
int a = 10;
int b = 9;
int c = a > b ? a : b;
int a = 10;
int b = 9;
int c = 998;
int abMax = (a > b) ? a : b;
int max = (abMax > c) ? abMax : c;
// 结果:max = 998;
标签:
原文地址:http://www.cnblogs.com/unique-ios/p/4266161.html