How to count the number of times we run a function in C

1 Answer

0 votes
#include <stdio.h>
 
int count_activation(void);
 
int main(void)
{
    count_activation();
    count_activation();
    printf("%d", count_activation());
    
    return 0;
}
int count_activation(void) 
{ 
    static int n = 0;
    
    n++;
    
    return n;
} 

  
/*
run:
 
3

*/

 



answered Nov 24, 2015 by avibootz

Related questions

...