当前位置:   article > 正文

运行下面程序,观察其输出,体会i++和++i的差别。_#include using namespace std;int main()

#include using namespace std;int main() int myage=39; int yourage=
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.     int myAge = 39;
  5.     int yourAge = 39;
  6.     cout << "I am: " << myAge << "years old." << endl;
  7.     cout << "you are :" << yourAge << "years old." << endl;
  8.     myAge++;
  9.     ++yourAge;
  10.     cout << "one year passes..." << endl;
  11.     cout << "I am: " << myAge << "years old." << endl;
  12.     cout << "you are :" << yourAge << "years old." << endl;
  13.     cout << "another year passes..." << endl;
  14.     cout << "I am: " << myAge++ << "years old." << endl;    //这里自加++后置,所以myAge先随cout输出再自加1
  15.     cout << "you are :" << ++yourAge << "years old." << endl;
  16.     cout << "Let's print it again." << endl;
  17.     cout << "I am: " << myAge << "years old." << endl;
  18.     cout << "you are :" << yourAge << "years old." << endl;
  19.     return 0;
  20. }

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号