c++ primer 6.1.2节练习答案
练习6.8
1 #ifndef FIRSTHEAD_H 2 #define FIRSTHEAD_H 3 int count_calls(); 4 int num; 5 #endif // !FIRSTHEAD_
头文件
1 int main() 2 { 3 cin >> num; 4 for (int i = 0; i != num; ++i) 5 cout << count_calls() << endl; 6 system("pause"); 7 return 0; 8 } 9 int count_calls() 10 { 11 static int ctr = 0; 12 if (ctr == 0) 13 { 14 ctr++; 15 return 0; 16 } 17 return ctr++; 18 19 }
源文件
浙公网安备 33010602011771号