C++学习笔记-1-自增和自减运算符
2015-07-19 15:19
405 查看
1. post-increment and pre-increment 的区别
来源:http://www.c4learn.com/c-programming/c-increment-operator/
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.
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.
来源:http://www.c4learn.com/c-programming/c-increment-operator/
#include<stdio.h> void main() { int a,b,x=10,y=10; 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++ 不用临时变量交换两个变量的值——函数对象
- 详解c++指针的指针和指针的引用
- C++std命名空间详解
- [C++ primer]优化内存分配
- 解决Eclipse中C++代码显示Symbol 'std' could not be resolved的问题
- 链表源代码(C语言实现)
- 链表源代码(C语言实现)
- NYOJ 113 字符串替换(C++STL解法)
- C++笔记
- 指针数组与二维数组的应用
- C++学习杂笔(总)
- C++学习笔记36 (模板的细节明确template specialization)和显式实例(template instantiation)
- C++四种类型的转换
- C语言 枚举(enum)、宏定义(#define)、结构体(struct)的一种联合应用
- 四、数组
- 三、流程控制
- 二、函数
- HDU 1087
- 一、第一个C程序
- 12天学好C语言——记录我的C语言学习之路(Day 1)