先看代码:
1 #include <stdio.h> 2 3 4 int main(int argc, char * argv[]) 5 { 6 int i = 0; 7 8 int j = 0; 9 if((++i>0)||(++j>0)) //注意理解||运算符,若第一个表达式为真,则不再运算第二个表达式了 10 { 11 printf("i=%d,j=%d\n", i,j); 12 13 } 14 int k = 0x01; 15 printf("0x01<<2+3 = %d\n", k<<2+3); //注意移位和+的优先级,先+ 16 17 i = 3; 18 int sum = (++i) + (++i) +(++i); 19 printf("sum = %d\n", sum); 20 21 i = 0; 22 for(i=0,printf("First = %d\n",i); 23 printf("second = %d\n",i),i<5; 24 i++,printf("Third = %d\n",i)) //注意理解for循环结构的运算原理过程 25 { 26 printf("Fourth = %d\n",i); 27 28 } 29 30 i = 3; 31 sum = ++i + ++i + ++i; //注意以空格分隔运算符,否则报错 32 printf("++i+++i+++i=%d\n",sum); 33 34 }
注:
1、此例中涉及||、for循环、++等知识点,只有准确理解了才能应用自如。
2、若第31行没有空格分隔时,编译时会报“error: lvalue required as increment operand”
GCC下编译运算结果: