从任何角度看,++ i和i + = 1有什么区别 [英] what is difference between ++i and i+=1 from any point of view

查看:138
本文介绍了从任何角度看,++ i和i + = 1有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是kn king的c编程提出的一个问题:一种现代方法.我不明白他给的解决方案:-

This is a question from kn king's c programming : a modern approach. I can't understand the solution given by him:-

The expression ++i is equivalent to (i += 1). The value of both expressions is i after 
the increment has been performed.

无论如何我如何理解?

How do I understand this anyway?

推荐答案

i = 10
printf("%d", i++);

将打印10,其中

printf("%d", ++i);

将打印11

X = i++可以这样认为

X = i
i = i + 1

其中X = ++i

i = i + 1
X = i

所以

printf ("%d", ++i); 

printf ("%d", i += 1);

但不是

printf ("%d", i++);

尽管在这三个语句中的任何一个之后的i值都相同.

although value of i after any of these three statements will be the same.

这篇关于从任何角度看,++ i和i + = 1有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆