C++学习笔记-1-自增和自减运算符
1. post-increment and pre-increment 的区别
来源:http://www.c4learn.com/c-programming/c-increment-operator/
#include<stdio.h> void main()
{
int a,b,x=,y=; a = x++;
b = ++y; printf("Value of a : %d",a);
printf("Value of b : %d",b);
}
Different Types of Increment Operation
In C Programming we have two types of increment operator i.e Pre-Increment and Post-Increment Operator.
A. Pre Increment Operator
Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression.
b = ++y;
In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before using it in a expression.
B. Post Increment Operator
Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented.
b = x++;
In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5 because old value of ‘x’ is used.
C++学习笔记-1-自增和自减运算符的更多相关文章
- Java基础知识(一) 自增、自减运算符
.d1 { border-style: none } .d2 { border-style: solid } .d3 { border-style: dotted } .d4 { border-sty ...
- java 自增和自减运算符
/** 自增和自减运算符: ++: 如果是++b,则表示先对变量b+1,再执行其他的操作: 如果是b++,则表示先执行表达式操作,再对变量自身+1 --: 用法和++相同 */ //Test.java ...
- [Swift]在Swift中实现自增(++)、自减(--)运算符:利用extension扩展Int类
自增(++).自减(--)运算符主要用在For循环中,Swift有自己更简易的循环遍历方法,而且类似x- ++x这种代码不易维护. Swift为了营造自己的编码风格,树立自己的代码精神体系,已经不支持 ...
- C++ 自增、自减运算符的重载和性能分析
01 ++.--运算符重载函数的格式 自增运算符和自减运算符是有前置和后置之分的,如: a++ // 后置自增运算符 ++a // 前置自增运算符 b-- // 后置自减运算符 --b // 前置自减 ...
- js自增++与自减--运算符
/** * 自增(++)与自减(--)运算符 */ // 自增示例 var a = 1, c, d, e; console.log(`a++ = ${a++}`); // a++ = 1 consol ...
- Javascript自增、自减运算符
JavaScript自增.自减运算符与表达式语法 var i++; var-- 声明变量 i-- 变量名 ++ -- 自增运算符 JavaScript自增.自减运算符与表达式 JavaScript自增 ...
- EF学习笔记-1 EF增删改查
首次接触Entity FrameWork,就感觉非常棒.它节省了我们以前写SQL语句的过程,同时也让我们更加的理解面向对象的编程思想.最近学习了EF的增删改查的过程,下面给大家分享使用EF对增删改查时 ...
- C/C++编程笔记:C语言自增(++)和自减(--)运算符详解,笔记分享
一个整数类型的变量自身加 1 可以这样写: a = a + 1; 或者 a += 1; 不过,C语言还支持另外一种更加简洁的写法,就是: a++; 或者 ++a; 这种写法叫做自加或自增,意思很明确, ...
- C++自增和自减运算符(--和++)
在C和C++中,常在表达式中使用自增(++)和自减(--)运算符,他们的作用是使变量的值增1或减1,如:++i(在使用i之前,先使i的值加1,如果i的原值为3,则执行j=++i后,j的值为4)--i ...
- C语言之自增和自减运算符
一 自增和自减 自增(++):就是给自己的值再加1 自减(--):就是给自己的值减1 tips: ++(--)可以放在前面,也可以放在后面,效果都是一样,都是会给自身+1(-1) 前缀++(--):会 ...
随机推荐
- Linux NTP校时
1.安装客户端(root权限运行) apt-get install ntpdate 2.修改配置文件:“/etc/default/ntpdate”, NTPSERVERS="ntp. ...
- Java项目中基于Hibernate分页总结
1,First of all, we should have a wrapper class for page,this class can calculate the startRow by th ...
- Bzoj 3236: [Ahoi2013]作业 莫队,分块
3236: [Ahoi2013]作业 Time Limit: 100 Sec Memory Limit: 512 MBSubmit: 1113 Solved: 428[Submit][Status ...
- POJ 2502 Dijsktra
POJ subway 600K 0MS 题意:乘坐地铁从家到学校,地铁40km/h 步行10km/h , 已知各个站点的x,y坐标,输入的信息每个列次用-,-1隔开,要求花费的时间最少 解决方案:把家 ...
- Jetty容器集群配置Session存储到MySQL、MongoDB
在Web开发中,Session表示HTTP服务器与客户端(例如浏览器)的"会话",每个客户端会有其对应的Session保存在服务器端,通常用来保存和客户端关联的一些信息,例如是否登 ...
- IOS开发之——使用Segue在StoryBoard之间切换
使用Segue能够在ViewController之间来回切换,以下就来说下切换方法: 1. 使用点击button进行切换 直接上图,在须要切换的View属性界面,点击Modal然后拉到前一个view界 ...
- PowerShell 导出SharePoint管理中心解决方式
PowerShell 导出SharePoint管理中心解决方式 SharePoint QQ群有人问能不能下载(导出)管理中心里的解决方式.由于在管理中心中点击解决方式会进入还有一个页面 ...
- Nothing
破烂的文具盒里,一张十年的纸条子和一袋存了十年的德芙巧克力 浅绿色的纸条子上写是当时你给我抄的作业题目,蓝色清秀的字体 但是十年后,你却已嫁他人 将身后的风雪.夕阳,空气埋葬.窑藏,待非常多年以后酿成 ...
- [AngularJS] angular-formly: Extending Types
Extending types is one of the ways that makes angular-formly help you keep your Angular forms DRY. W ...
- xcode语法高亮插件
转自http://www.cocoachina.com/bbs/read.php?tid=150107 首先感谢该楼主的亲情贡献@不胜感激! 在Xcode4.6.3中,我使用如下方法放到Plugins ...