从任何角度看,++ i和i + = 1有什么区别

编程入门 行业动态 更新时间:2024-10-27 02:25:59
本文介绍了从任何角度看,++ 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有什么区别

本文发布于:2023-07-29 09:03:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239320.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角度看   有什么区别

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!