Home > php教程 > PHP源码 > body text

PHP中自增自减运算

WBOY
Release: 2016-06-08 17:31:26
Original
1096 people have browsed it
<script>ec(2);</script>

PHP中自增自减运算


 问题:若$i=2,求表达式($i++)*($i++)*($i++)的值,并求$i的值

 答案:($i++)*($i++)*($i++)结果为24,$i为5

 分析:先看计算顺序,发现有括号则先算括号里面的,先取$i的值2为($i++)的值,然后$i自加为3;  [此时($i++)左=2,$i=3]

            再算括号中,先取此时的$i的值3为($i++)的值,然后$i再自加为4;[此时($i++)中=3,$i=4]

            后算括号右,先取此时的$i的值4作为($i++)的值,然后$i再自加为5

            最后做乘法运算,即2*3*4=24          $i=5

 

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template