i++ 与 ++i day3

下面代码的执行结果是

 1  i++    先取 i  的值,再对 i 的值加上1
 2  ++i   先对i 的值加 1,在取i 的值
 3 
 4 
 5 public class TestFunction {
 6     
 7      public static void main(String[] args) {
 8          int student=1;
 9         System.out.println(++student+student++);
10     }
11 }
12 
13 步骤            i 的原始值          i处理后的值               表达式的值
14 ++i              1                     2                                   2
15 i++              2                     3                                   2
16 
17 所以结果是  4

猜你喜欢

转载自www.cnblogs.com/satisfysmy/p/9840415.html
i++
今日推荐