累加运算符的特征举例

     var x = 1;
     console.log(x); //1
     console.log(x++); //1
     console.log(x); //2
     console.log("----------分割线----------");
     var y = 1;
     console.log(y); //1
     console.log(++y); //2
     console.log(y); //2

            int x = 1;
            Response.Write(x); //1
            Response.Write("
"); Response.Write(x++); //1 Response.Write("
"); Response.Write(x); //2 Response.Write("
"); int y = 1; Response.Write(y); //1 Response.Write("
"); Response.Write(++y); //2 Response.Write("
"); Response.Write(y); //2

    

不管这个++放在变量前面还是放在变量后面,变量返回值都是原变量数值加1后的结果;

++x 是把累加符号放在变量前,当时返回结果是增加1后的结果;

y++ 是把累加符号放在变量后,当时返回结果还是变量参与当前运算之前的数值;


你可能感兴趣的:(累加运算符的特征举例)