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-自增和自减运算符的更多相关文章

  1. Java基础知识(一) 自增、自减运算符

    .d1 { border-style: none } .d2 { border-style: solid } .d3 { border-style: dotted } .d4 { border-sty ...

  2. java 自增和自减运算符

    /** 自增和自减运算符: ++: 如果是++b,则表示先对变量b+1,再执行其他的操作: 如果是b++,则表示先执行表达式操作,再对变量自身+1 --: 用法和++相同 */ //Test.java ...

  3. [Swift]在Swift中实现自增(++)、自减(--)运算符:利用extension扩展Int类

    自增(++).自减(--)运算符主要用在For循环中,Swift有自己更简易的循环遍历方法,而且类似x- ++x这种代码不易维护. Swift为了营造自己的编码风格,树立自己的代码精神体系,已经不支持 ...

  4. C++ 自增、自减运算符的重载和性能分析

    01 ++.--运算符重载函数的格式 自增运算符和自减运算符是有前置和后置之分的,如: a++ // 后置自增运算符 ++a // 前置自增运算符 b-- // 后置自减运算符 --b // 前置自减 ...

  5. js自增++与自减--运算符

    /** * 自增(++)与自减(--)运算符 */ // 自增示例 var a = 1, c, d, e; console.log(`a++ = ${a++}`); // a++ = 1 consol ...

  6. Javascript自增、自减运算符

    JavaScript自增.自减运算符与表达式语法 var i++; var-- 声明变量 i-- 变量名 ++ -- 自增运算符 JavaScript自增.自减运算符与表达式 JavaScript自增 ...

  7. EF学习笔记-1 EF增删改查

    首次接触Entity FrameWork,就感觉非常棒.它节省了我们以前写SQL语句的过程,同时也让我们更加的理解面向对象的编程思想.最近学习了EF的增删改查的过程,下面给大家分享使用EF对增删改查时 ...

  8. C/C++编程笔记:C语言自增(++)和自减(--)运算符详解,笔记分享

    一个整数类型的变量自身加 1 可以这样写: a = a + 1; 或者 a += 1; 不过,C语言还支持另外一种更加简洁的写法,就是: a++; 或者 ++a; 这种写法叫做自加或自增,意思很明确, ...

  9. C++自增和自减运算符(--和++)

    在C和C++中,常在表达式中使用自增(++)和自减(--)运算符,他们的作用是使变量的值增1或减1,如:++i(在使用i之前,先使i的值加1,如果i的原值为3,则执行j=++i后,j的值为4)--i ...

  10. C语言之自增和自减运算符

    一 自增和自减 自增(++):就是给自己的值再加1 自减(--):就是给自己的值减1 tips: ++(--)可以放在前面,也可以放在后面,效果都是一样,都是会给自身+1(-1) 前缀++(--):会 ...

随机推荐

  1. JavaScript高级程序设计49.pdf

    HTML5事件 contextmenu事件 contextmenu事件是冒泡的,可以将事件处理程序指定到document,这个事件的目标是用户操作的元素,在兼容DOM的浏览器中使用event.prev ...

  2. webstorage调查资料汇总

    在调查webstorage的过程中,一步一步了解了各种缓存或存储机制,local storage本地存储,application cache离线应用存储,http cache是http本身自带的缓存机 ...

  3. Shell until循环

    until 循环执行一系列命令直至条件为 true 时停止.until 循环与 while 循环在处理方式上刚好相反.一般while循环优于until循环,但在某些时候,也只是极少数情况下,until ...

  4. Overview of the Packages JAXP

    The SAX and DOM APIs are defined by the XML-DEV group and by the W3C, respectively. The libraries th ...

  5. SOA技术的进化史

    SOA 是一种程序设计思想,其实早在远古时代(计算机史)它就已经出现了.无非就是把系统分解,将数据和业务逻辑部分尽量独立出来,然后以服务形式提供给另外的系统共用. 那时也有一些可以实现 SOA 的工具 ...

  6. iOS实用技能扩展-静态库的制作与简单使用

    前言:此文是关于静态库的概念描述,如何制作及简单调试使用,不同版本的说明与场景使用. 1.关于库的简介: 库可以分为2种类型 开源库 公开源代码,能看到具体实现 比如SDWebImage.AFNetw ...

  7. VC++深入详解-第一章学习心得(二)

    前面介绍到了注册窗口,接下来进行窗口的创建,利用CreateWindow函数,结构如下 CreateWindowExW( DWORD dwExStyle, LPCWSTR lpClassName, / ...

  8. PowerMock注解PowerMockIgnore的使用方法

    故事要从一个异常开始,某天我在开发一个加密.解密特性,算法使用的是3DES,样例代码如下. package org.jackie.study.powermock; import java.io.Uns ...

  9. UDP编程

    一: socket编程中的几种地址 Socket编程会遇到三种地址, 都是定义的结构体(struct): Struct in_addr     {         Unsigned int s_add ...

  10. JAVA对象之生

    https://yq.aliyun.com/users/1556056716932876?spm=5176.100239.blogrightarea55811.3.6cvyJd