How to declare and use static variables in C

1 Answer

0 votes
#include <stdio.h> 
 
int f(void);
 
int main(int argc, char **argv) 
{
	f();
	f();
	printf("%d\n", f());
		
	return 0;
}
int f(void)
{
	static int number = 0;
	
	number++;
 
	return number;
}
 
 
/*
run:
 
3
 
*/

 



answered Feb 23, 2016 by avibootz

Related questions

1 answer 200 views
1 answer 195 views
1 answer 207 views
1 answer 187 views
1 answer 173 views
1 answer 182 views
1 answer 112 views
...