一个函数的调用次数

可以通过在函数体里定义一个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 }

 

 

posted @ 2012-05-03 07:21  zhengmian  阅读(779)  评论(0)    收藏  举报