C++编程思想 第1卷 第3章 自增和自减

自增和自减运算符改变循环变量控制循环
自减运算符是 -- ,意思是 减少一个单位
自增运算符是 ++ 意思是 增加一个单位
++A 先运算 再使用

A++ 先使用 再运算


//: C03:AutoIncrement.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Shows use of auto-increment
// and auto-decrement operators.
#include <iostream>
using namespace std;

int main() {
  int i = 0;
  int j = 0;
  cout << ++i << endl; // Pre-increment
  cout << j++ << endl; // Post-increment
  cout << --i << endl; // Pre-decrement
  cout << j-- << endl; // Post decrement
  getchar();
} ///:~

输出
1
0
0
1


猜你喜欢

转载自blog.csdn.net/eyetired/article/details/80589518