一个函数的调用次数

可以通过在函数体里定义一个static 变量实现记录调用函数的次数:

 

 1 #include <stdio.h>
 2 
 3  // 函数调用的次数
 4  void test_static_used_times()
 5 {
 6      static  int times= 0;
 7 
 8     times++;
 9     printf( " %d\n ",times);
10 }
11 
12  int main()
13 {
14      int i= 0;
15 
16      while(i< 10)
17     {
18         test_static_used_times();
19 
20         i++;
21     }
22 
23      return  0;
24 }

 

 

转载于:https://www.cnblogs.com/zhengmian/archive/2012/05/03/function_use_times.html