++i 与 i++ 的区别,区别_PHP教程

WBOY
Release: 2016-07-12 08:50:24
Original
1278 people have browsed it

++i 与 i++ 的区别,区别

1、++i 的用法(以 a=++i ,i=2 为例)

   先将 i 值加 1 (也就是 i=i+1 ),然后赋给变量 a (也就是 a=i ), 

   则最终 a 值等于 3 , i 值等于 3 。

   所以 a=++i 相当于 i=i+1 ,a=i

2、i++ 的用法(以 a=i++ ,i=2 为例)

   先将 i 值赋给变量 a (也就是 a=i ),然后 i 值加 1 (也就是 i=i+1 ),

   则最终 a 值等于 2 ,i 值等于 3 。

   所以 a=i++ 相当于 a=i , i=i+1 

3、++i 与 i++

   a=++i 相当于 i++ , a=i   

   a=i++ 相当于 a=i , i++

4、++i 与 i++ 单独使用时,相当于 i=i+1

   如果赋给一个新变量,则 ++i 先将 i 值加 1 ,而 i++ 先将 i 赋给新变量。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133573.htmlTechArticle++i 与 i++ 的区别,区别 1、++i 的用法(以 a=++i ,i=2 为例) 先将 i 值加 1 (也就是 i=i+1 ),然后赋给变量 a (也就是 a=i ), 则最终 a 值等...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!