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 201 views
1 answer 196 views
1 answer 208 views
1 answer 189 views
1 answer 174 views
1 answer 183 views
1 answer 114 views
...