for循环中的i++和++i
直接上代码。。。。。。。。。。。。。
#include <iostream> using namespace std; int main()
{
int i, k,l,p;
k = 0;
p = 0; for (i = 0; i < 10; k = i, ++i)
{
cout << "---\n" << endl;
cout << k << endl;
cout << i << endl;
} cout << "i====== \n" <<i<< endl;
cout << "\\\\\\\\\\\n" << endl; for (l = 0; l < 10; p = l, l++)
{
cout << "---\n" << endl;
cout << p << endl;
cout << l << endl;
}
cout << "l====== \n" << l << endl; system("pause");
}
从结果我们可以看出这样几点:
1.for循环先执行前两个分号内的内容,然后执行大括号的内容,最后执行第二个分号后的内容
2.在++i和i++的形式下i都完成了i=i+1的操作,这个操作在这个地方不分先后。因为最后都是吧i+1赋给了原来的i
由此可知,在for循环中是没有区别的
第一种:

第二种

for循环中的i++和++i的更多相关文章
- for循环中i--的妙用 及 两变量互换数值的问题
int[] array = new int[4]; for(int i = 0; i < array.length; i++){ array[i] = (int)(Math.random() * ...
- Python 之 for循环中的lambda
第一种 f = [lambda x: x*i for i in range(4)] (如果将x换成i,调用时候就不用传参数,结果都为3) 对于上面的表达式,调用结果: >>> f ...
- 在jquery中each循环中,要用return false代替break,return true代替continue。
在jquery中each循环中,要用return false代替break,return true代替continue. $.each(data, function (n, value) { if(v ...
- JavaScript形而上的For循环中的Break
break相当于循环中的GOTO,需避免使用. 下面是一个break使用例子. 找出第一个months小于7的项目. const cats = [ { name: 'Mojo', months: 84 ...
- vue 如何在循环中 "监听" 的绑定v-model数据
vue 如何在循环中 "监听" 的绑定v-model数据 阅读目录 vue 如何在循环中 "监听" 的绑定v-model数据 1. 普通属性的值进行监听 2. ...
- Java循环中try...finally...遇到continue
一段很简单的代码,先自己在大脑中给出结果: for (int i = 0; i < 5; i++) { System.out.println("enter: i=" + i) ...
- 浅谈循环中setTimeout执行顺序问题
浅谈循环中setTimeout执行顺序问题 (下面有见解一二) 期望:开始输出一个0,然后每隔一秒依次输出1,2,3,4. for (var i = 0; i < 5; i++) { setTi ...
- django for 循环中,获取序号
模板的for循环中,如何获取序号? 想过用enumerate,但是在模板中会报错 Could not parse the remainder xxx: 后来搜到 forloop.counter,完美解 ...
- JS如何获取PHP循环中的ID
JS如何获取PHP循环中的ID kaalrz 二路公交车 结帖率:83.33% 首先抱歉,因为昨天那帖图片几次都不能用,修改到不能再次修改,今天早上回帖又提示没有这个帖,只好重发一次. 如 ...
- for循环中 i++和++i 是否有区别?
正常情况下 i++和++i是有区别的: 前者是:先引用,后增加, 后者是:先增加,后引用, 但是在for循环中: for(var i=0;i<10;i++){ System.out.print ...
随机推荐
- Spine with Unity Mecanim
前言 最近这两天刚刚接触Spine,研究了一下Unity Mecanim Animator如何控制Spine,在此分享记录一下,如有不当之处,请留言指出,欢迎讨论. Unity & Spine ...
- JavaScript学习笔记(二)——函数和数组
第二章 函数简介 1 第一个函数示例 <script language="JavaScript" type="text/JavaScript"> f ...
- Tensorflow - Implement for a Convolutional Neural Network on MNIST.
Coding according to TensorFlow 官方文档中文版 中文注释源于:tf.truncated_normal与tf.random_normal TF-卷积函数 tf.nn.con ...
- Paper Reading - Mind’s Eye: A Recurrent Visual Representation for Image Caption Generation ( CVPR 2015 )
Link of the Paper: https://ieeexplore.ieee.org/document/7298856/ A Correlative Paper: Learning a Rec ...
- Paper Reading - Im2Text: Describing Images Using 1 Million Captioned Photographs ( NIPS 2011 )
Link of the Paper: http://papers.nips.cc/paper/4470-im2text-describing-images-using-1-million-captio ...
- 微软职位内部推荐-Senior Software Engineer II-Sharepoint
微软近期Open的职位: SharePoint is a multi-billion dollar enterprise business that has grown from an on-prem ...
- 20170928-3 四则运算psp
1.本周psp: 2.本周进度条: 3.累计进度图(折线图): 4.psp饼状图:
- 1029C语言文法的理解
<程序>→<外部声明>|<程序><外部声明> <外部声明>→<函数定义>|<声明> <函数定义>→< ...
- (十一)Jmeter另一种调试工具 HTTP Mirror Server
之前我介绍过Jmeter的一种调试工具Debug Sampler,它可以输出Jmeter的变量.属性甚至是系统属性而不用发送真实的请求到服务器.既然这样,那么HTTP Mirror Server又是做 ...
- 有一个集合,判断集合里有没有“world”这个元素,如果有,添加“javaee”
// 有一个集合,判断集合里有没有“world”这个元素,如果有,添加“javaee” List list = new ArrayList(); list.add("world") ...