自考新教材--p109

源程序:

#include <iostream>

using namespace std;

static int glos = 100;

void f()

{

  int a = 1;

  static int fs = 1;

  cout << "在f中:a(自动)=" << a << " fs(静态)=" << fs << " glos(静态)=" << glos << endl;

  a += 2;

  fs += 2;

  glos += 10;

  cout << "在f中:a(自动)=" << a << " fs(静态)=" << fs << " glos(静态)=" << glos << endl;

}

int main()

{

  static int ms = 10;

  for (int i = 1; i <= 3; i++)

    f();

  cout << "ms=" << ms << endl;

  cout << "glos=" << glos << endl;

  system("pause");

  return 0;

}

运行结果:

 

猜你喜欢

转载自www.cnblogs.com/duanqibo/p/12081984.html